Skip to content

Commit e0dbb4d

Browse files
committed
feat(docs): add PostHog analytics with reverse proxy
Set up posthog-js with instrumentation-client.ts for privacy-friendly product analytics. Route events through /ingest/* reverse proxy to bypass ad blockers. Env vars configured in Vercel dashboard.
1 parent 44e44d7 commit e0dbb4d

6 files changed

Lines changed: 102 additions & 0 deletions

File tree

bun.lock

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_api_key_here
2+
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ yarn-debug.log*
2121
yarn-error.log*
2222

2323
# others
24+
.env
2425
.env*.local
2526
.vercel
2627
next-env.d.ts

docs/next.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ const withMDX = createMDX();
55
/** @type {import('next').NextConfig} */
66
const config = {
77
reactStrictMode: true,
8+
skipTrailingSlashRedirect: true,
89
async rewrites() {
910
return [
1011
{
1112
source: '/docs/:path*.mdx',
1213
destination: '/llms.mdx/docs/:path*',
1314
},
15+
16+
// PostHog reverse proxy
17+
{
18+
source: '/ingest/static/:path*',
19+
destination: 'https://us-assets.i.posthog.com/static/:path*',
20+
},
21+
{
22+
source: '/ingest/:path*',
23+
destination: 'https://us.i.posthog.com/:path*',
24+
},
1425
];
1526
},
1627
};

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lucide-react": "^0.563.0",
2020
"motion": "^12.34.1",
2121
"next": "16.1.6",
22+
"posthog-js": "^1.350.0",
2223
"react": "^19.2.4",
2324
"react-dom": "^19.2.4",
2425
"tailwind-merge": "^3.4.0"

docs/src/instrumentation-client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import posthog from 'posthog-js'
2+
3+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
4+
api_host: '/ingest',
5+
ui_host: 'https://us.posthog.com',
6+
capture_pageview: true,
7+
capture_pageleave: true,
8+
capture_exceptions: true,
9+
debug: process.env.NODE_ENV === 'development',
10+
})

0 commit comments

Comments
 (0)