Enable Google Analytics or Google Tag Manager
Add Google Analytics or Google Tag Manager tracking to your website by setting one environment variable. No coding required.
You can track visitors and user behavior on your website using either Google Analytics or Google Tag Manager. The setup is simple. Just add one environment variable in your deployment platform. Do not add both. Choose only one method.
Option 1: Google Analytics
If you want direct tracking without Tag Manager, use this method.
Add this environment variable in your deployment settings:
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=G-XXXXXXXXXXReplace G-XXXXXXXXXX with your real Google Analytics Measurement ID.
If you need help creating the ID, follow this step by step guide:
sujalvanjare.com/blog/how-to-add-google-analytics-nextjs-15
Once added and deployed, tracking will start automatically.
Option 2: Google Tag Manager
Google Tag Manager gives you more control. You can manage analytics, events, pixels and other tracking scripts from one dashboard.
Add this environment variable:
NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-XXXXXXXReplace GTM-XXXXXXX with your Tag Manager Container ID.
To learn how to create a Tag Manager setup and connect Google Analytics 4 inside it, check these guides:
sujalvanjare.com/blog/integrate-google-tag-manager-nextjs-15
sujalvanjare.com/blog/add-google-analytics-4-to-google-tag-manager
After deployment, Tag Manager will automatically load on your site.
Important Notes
- Use only one setup. Either Google Analytics or Google Tag Manager. Not both.
- Add the environment variable only in your production deployment like Vercel. Local development does not need tracking.
- No code changes are required. The system detects the environment variable and activates tracking automatically.
Finished
Once the environment variable is added and deployed, your tracking system will be active and your analytics dashboard will start collecting data.

