Skip to content

Fix: Google Analytics implementation with environment variables#5

Merged
un33k merged 1 commit intomainfrom
fix/analythics
Sep 5, 2025
Merged

Fix: Google Analytics implementation with environment variables#5
un33k merged 1 commit intomainfrom
fix/analythics

Conversation

@un33k
Copy link
Member

@un33k un33k commented Sep 5, 2025

Summary

  • Fixed Google Analytics implementation to work properly with Next.js
  • Created GoogleAnalytics component using Next.js Script component
  • Moved from _document.tsx to _app.tsx for proper environment variable access
  • Only loads if NEXT_PUBLIC_GA_MEASUREMENT_ID is set
  • Keeps tracking ID private and out of open source code

Implementation Details

  • Uses Next.js Script component with afterInteractive strategy
  • Properly reads client-side environment variables
  • No tracking without explicit configuration

Test plan

  • Without .env.local - verify no Google Analytics scripts load
  • With NEXT_PUBLIC_GA_MEASUREMENT_ID=G-GC4F593HEQ in .env.local
  • Verify Google Analytics scripts load in page source
  • Check that gtag is properly initialized in console
  • Verify analytics events are tracked in GA dashboard

🤖 Generated with Claude Code

- Google Analytics only loads if NEXT_PUBLIC_GA_MEASUREMENT_ID is set
- Added GoogleAnalytics component using Next.js Script component
- Moved analytics to _app.tsx for proper client-side environment variable access
- Added .env.example with optional GA configuration
- Keeps tracking ID private and out of open source code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Sep 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
btc Ready Ready Preview Comment Sep 5, 2025 11:26pm

@un33k un33k merged commit ba47c0e into main Sep 5, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant