From 7e42218ab9a89f84e7d3084eda1def591bd6ba26 Mon Sep 17 00:00:00 2001 From: Satya Patel Date: Fri, 12 Dec 2025 22:03:19 -0500 Subject: [PATCH 1/2] feat: add PostHog analytics to web and marketing apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add posthog-js to web and marketing apps - Create instrumentation-client.ts for both apps with auto pageview/pageleave tracking - Add PostHogUserIdentifier component for web app (syncs Clerk user to PostHog) - Add CookieConsent component for marketing app (GDPR opt-out by default) - Configure Next.js rewrites for /ingest proxy (bypasses ad blockers) - Add ANALYTICS_CONSENT_KEY to shared constants for cross-app persistence - Add NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST env vars 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .env.example | 4 + apps/marketing/next.config.ts | 10 +++ apps/marketing/package.json | 1 + apps/marketing/src/app/layout.tsx | 3 + .../CookieConsent/CookieConsent.tsx | 73 +++++++++++++++++++ .../src/components/CookieConsent/index.ts | 1 + apps/marketing/src/env.ts | 7 ++ apps/marketing/src/instrumentation-client.ts | 29 ++++++++ apps/web/next.config.ts | 10 +++ apps/web/package.json | 1 + apps/web/src/app/layout.tsx | 2 + .../PostHogUserIdentifier.tsx | 24 ++++++ .../components/PostHogUserIdentifier/index.ts | 1 + apps/web/src/env.ts | 7 ++ apps/web/src/instrumentation-client.ts | 22 ++++++ bun.lock | 14 ++++ packages/shared/src/constants.ts | 3 + 17 files changed, 212 insertions(+) create mode 100644 apps/marketing/src/components/CookieConsent/CookieConsent.tsx create mode 100644 apps/marketing/src/components/CookieConsent/index.ts create mode 100644 apps/marketing/src/instrumentation-client.ts create mode 100644 apps/web/src/components/PostHogUserIdentifier/PostHogUserIdentifier.tsx create mode 100644 apps/web/src/components/PostHogUserIdentifier/index.ts create mode 100644 apps/web/src/instrumentation-client.ts diff --git a/.env.example b/.env.example index 83145f284ae..d3743ec49cf 100644 --- a/.env.example +++ b/.env.example @@ -27,3 +27,7 @@ BLOB_READ_WRITE_TOKEN=your_blob_token_here # Desktop App VITE_DEV_SERVER_PORT=4927 DESKTOP_AUTH_SECRET=your_desktop_auth_secret_here_min_32_chars + +# PostHog Analytics +NEXT_PUBLIC_POSTHOG_KEY=your_posthog_project_api_key_here +NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com diff --git a/apps/marketing/next.config.ts b/apps/marketing/next.config.ts index c9b9e812a6c..52f81bc9d9a 100644 --- a/apps/marketing/next.config.ts +++ b/apps/marketing/next.config.ts @@ -11,6 +11,16 @@ const config: NextConfig = { reactStrictMode: true, reactCompiler: true, typescript: { ignoreBuildErrors: true }, + rewrites: async () => [ + { + source: "/ingest/static/:path*", + destination: "https://us-assets.i.posthog.com/static/:path*", + }, + { + source: "/ingest/:path*", + destination: "https://us.i.posthog.com/:path*", + }, + ], }; export default config; diff --git a/apps/marketing/package.json b/apps/marketing/package.json index 6c0656c0c35..f3371da3f55 100644 --- a/apps/marketing/package.json +++ b/apps/marketing/package.json @@ -22,6 +22,7 @@ "lucide-react": "^0.560.0", "next": "^16.0.10", "next-themes": "^0.4.6", + "posthog-js": "^1.306.1", "react": "^19.2.3", "react-dom": "^19.2.3", "react-fast-marquee": "^1.6.5", diff --git a/apps/marketing/src/app/layout.tsx b/apps/marketing/src/app/layout.tsx index e6c95fbc026..921225dc1fe 100644 --- a/apps/marketing/src/app/layout.tsx +++ b/apps/marketing/src/app/layout.tsx @@ -7,6 +7,8 @@ import { ThemeProvider } from "next-themes"; import { env } from "@/env"; +import { CookieConsent } from "@/components/CookieConsent"; + import { CTAButtons } from "./components/CTAButtons"; import { Footer } from "./components/Footer"; import { Header } from "./components/Header"; @@ -59,6 +61,7 @@ export default function RootLayout({
} /> {children}