Skip to content

Commit a713373

Browse files
authored
Analytics (#10)
1 parent 442d632 commit a713373

File tree

13 files changed

+120
-9
lines changed

13 files changed

+120
-9
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ CLERK_SECRET_KEY=some-secret-key
2222

2323
# Uploadthing
2424
UPLOADTHING_TOKEN='uploadthing-token'
25+
26+
# Posthog
27+
NEXT_PUBLIC_POSTHOG_KEY=some-posthog-key
28+
NEXT_PUBLIC_POSTHOG_HOST=the-posthog-host

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Tracking progress on key features and tasks for the project.
8989
- [x] 🔗 Sync folder open state with the URL
9090
- [x] 🔐 Implement user authentication
9191
- [x] 📁 Enable file upload functionality
92-
- [ ] 📊 Add analytics tracking
92+
- [x] 📊 Add analytics tracking
9393

9494
### 📝 Note from 5-28-2025
9595

netlify.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[redirects]]
2+
from = "/ingest/static/*"
3+
to = "https://us-assets.i.posthog.com/static/:splat"
4+
host = "us-assets.i.posthog.com"
5+
status = 200
6+
force = true
7+
8+
[[redirects]]
9+
from = "/ingest/*"
10+
to = "https://us.i.posthog.com/:splat"
11+
host = "us.i.posthog.com"
12+
status = 200
13+
force = true

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"lucide-react": "^0.511.0",
3232
"mysql2": "^3.14.1",
3333
"next": "^15.2.3",
34+
"posthog-js": "^1.257.0",
3435
"react": "^19.0.0",
3536
"react-dom": "^19.0.0",
3637
"tailwind-merge": "^3.3.0",

pnpm-lock.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
3+
import posthog from "posthog-js";
4+
import { PostHogProvider as PHProvider } from "posthog-js/react";
5+
import { useEffect } from "react";
6+
7+
import UserIdentification from "./user-identification";
8+
9+
import { env } from "~/env";
10+
11+
export function PostHogProvider({ children }: { children: React.ReactNode }) {
12+
useEffect(() => {
13+
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
14+
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
15+
person_profiles: "identified_only", // or 'always' to create profiles for anonymous users as well
16+
defaults: "2025-05-24",
17+
});
18+
}, []);
19+
20+
return (
21+
<PHProvider client={posthog}>
22+
<UserIdentification />
23+
{children}
24+
</PHProvider>
25+
);
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useUser } from "@clerk/nextjs";
2+
import { usePostHog } from "posthog-js/react";
3+
import { useEffect } from "react";
4+
5+
export default function UserIdentification() {
6+
const posthog = usePostHog();
7+
const { user } = useUser();
8+
9+
useEffect(() => {
10+
if (user) {
11+
posthog.identify(user.id, {
12+
email: user.emailAddresses[0]?.emailAddress,
13+
});
14+
} else {
15+
posthog.reset();
16+
}
17+
}, [posthog, user]);
18+
19+
return null; // Do not render anything
20+
}

src/app/f/[folderId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z } from "zod";
22

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

5-
import DriveContents from "../../drive-contents";
5+
import DriveContents from "../drive-contents";
66

77
export default async function GoogleDriveClone(props: {
88
params: Promise<{ folderId: number }>;
File renamed without changes.

0 commit comments

Comments
 (0)