This project uses @next/third-parties for integrating Google Analytics and Google Tag Manager in a Next.js optimized way.
- Package:
@next/third-parties/google
- Component:
GoogleAnalytics
- Documentation: Next.js Google Analytics
import { GoogleAnalytics } from '@next/third-parties/google'
// Usage in layout.tsx
{env.NEXT_PUBLIC_GA_ID && isProduction && <GoogleAnalytics gaId={env.NEXT_PUBLIC_GA_ID} />}
- Package:
@next/third-parties/google
- Component:
GoogleTagManager
- Documentation: Next.js Google Tag Manager
import { GoogleTagManager } from '@next/third-parties/google'
// Usage in layout.tsx
{env.NEXT_PUBLIC_GTM_ID && isProduction && <GoogleTagManager gtmId={env.NEXT_PUBLIC_GTM_ID} />}
Required environment variables for analytics setup (optional features):
Variable | Purpose | Required |
---|---|---|
NEXT_PUBLIC_GA_ID |
Google Analytics Measurement ID | No |
NEXT_PUBLIC_GTM_ID |
Google Tag Manager Container ID | No |
For detailed environment variable setup, refer to Environment Variables Documentation.