Skip to content

Commit 3c6525d

Browse files
kawaijoeclaude
andauthored
Add Google Analytics to docs site (#858)
Use @next/third-parties GoogleAnalytics component to track usage on forui.dev. The measurement ID is passed via GitHub Actions environment variable (docs-production only) to ensure analytics only loads in production, not in preview deployments. Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent d2427e2 commit 3c6525d

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/docs_deploy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
6666
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
6767
NEXT_PUBLIC_SNIPPETS_URL: ${{ vars.SNIPPETS_URL }}
68+
NEXT_PUBLIC_GA_MEASUREMENT_ID: ${{ vars.GA_MEASUREMENT_ID }}
6869
run: pnpm run deploy ${{ vars.DEPLOY_ARGS }}
6970

7071
docs_snippets:

docs/app/layout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RootProvider } from 'fumadocs-ui/provider/next';
2+
import { GoogleAnalytics } from '@next/third-parties/google';
23
import './global.css';
34
import { Inter } from 'next/font/google';
45

@@ -27,6 +28,9 @@ export default function Layout({ children }: LayoutProps<'/'>) {
2728
<body className="flex flex-col min-h-screen">
2829
<RootProvider>{children}</RootProvider>
2930
</body>
31+
{process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID && (
32+
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID} />
33+
)}
3034
</html>
3135
);
3236
}

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
1616
},
1717
"dependencies": {
18+
"@next/third-parties": "^16.1.6",
1819
"@opennextjs/cloudflare": "^1.14.8",
1920
"@radix-ui/react-accordion": "^1.2.12",
2021
"@radix-ui/react-alert-dialog": "^1.1.15",

docs/pnpm-lock.yaml

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

0 commit comments

Comments
 (0)