Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ CLERK_SECRET_KEY=some-secret-key

# Uploadthing
UPLOADTHING_TOKEN='uploadthing-token'

# Posthog
NEXT_PUBLIC_POSTHOG_KEY=some-posthog-key
NEXT_PUBLIC_POSTHOG_HOST=the-posthog-host
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Tracking progress on key features and tasks for the project.
- [x] πŸ”— Sync folder open state with the URL
- [x] πŸ” Implement user authentication
- [x] πŸ“ Enable file upload functionality
- [ ] πŸ“Š Add analytics tracking
- [x] πŸ“Š Add analytics tracking

### πŸ“ Note from 5-28-2025

Expand Down
13 changes: 13 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[redirects]]
from = "/ingest/static/*"
to = "https://us-assets.i.posthog.com/static/:splat"
host = "us-assets.i.posthog.com"
status = 200
force = true

[[redirects]]
from = "/ingest/*"
to = "https://us.i.posthog.com/:splat"
host = "us.i.posthog.com"
status = 200
force = true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"lucide-react": "^0.511.0",
"mysql2": "^3.14.1",
"next": "^15.2.3",
"posthog-js": "^1.257.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwind-merge": "^3.3.0",
Expand Down
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
26 changes: 26 additions & 0 deletions src/app/_providers/posthog-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";

import posthog from "posthog-js";
import { PostHogProvider as PHProvider } from "posthog-js/react";
import { useEffect } from "react";

import UserIdentification from "./user-identification";

import { env } from "~/env";

export function PostHogProvider({ children }: { children: React.ReactNode }) {
useEffect(() => {
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: "identified_only", // or 'always' to create profiles for anonymous users as well
defaults: "2025-05-24",
});
}, []);

return (
<PHProvider client={posthog}>
<UserIdentification />
{children}
</PHProvider>
);
}
20 changes: 20 additions & 0 deletions src/app/_providers/user-identification.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useUser } from "@clerk/nextjs";
import { usePostHog } from "posthog-js/react";
import { useEffect } from "react";

export default function UserIdentification() {
const posthog = usePostHog();
const { user } = useUser();

useEffect(() => {
if (user) {
posthog.identify(user.id, {
email: user.emailAddresses[0]?.emailAddress,
});
} else {
posthog.reset();
}
}, [posthog, user]);

return null; // Do not render anything
}
2 changes: 1 addition & 1 deletion src/app/f/[folderId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";

import * as queries from "~/server/db/queries";

import DriveContents from "../../drive-contents";
import DriveContents from "../drive-contents";

export default async function GoogleDriveClone(props: {
params: Promise<{ folderId: number }>;
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import "~/styles/globals.css";

import { ClerkProvider } from "@clerk/nextjs";
import { type Metadata } from "next";
import { Geist } from "next/font/google";

import { PostHogProvider } from "./_providers/posthog-provider";

import "~/styles/globals.css";

export const metadata: Metadata = {
title: "Drive Tutorial",
description: "It's like Google Drive, but worse!",
Expand All @@ -20,9 +22,11 @@ export default function RootLayout({
}: Readonly<{ children: React.ReactNode }>) {
return (
<ClerkProvider>
<html lang="en" className={`${geist.variable}`}>
<body>{children}</body>
</html>
<PostHogProvider>
<html lang="en" className={`${geist.variable}`}>
<body>{children}</body>
</html>
</PostHogProvider>
</ClerkProvider>
);
}
6 changes: 4 additions & 2 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const env = createEnv({
* `NEXT_PUBLIC_`.
*/
client: {
// NEXT_PUBLIC_CLIENTVAR: z.string(),
NEXT_PUBLIC_POSTHOG_KEY: z.string(),
NEXT_PUBLIC_POSTHOG_HOST: z.string(),
},

/**
Expand All @@ -37,7 +38,8 @@ export const env = createEnv({
SINGLESTORE_HOST: process.env.SINGLESTORE_HOST,
SINGLESTORE_PORT: process.env.SINGLESTORE_PORT,
SINGLESTORE_DATABASE: process.env.SINGLESTORE_DATABASE,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
Expand Down