This document explains how to configure environment variables for Google Analytics and Google AdSense integration.
Create a .env.local file in the root directory with the following variables:
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX- Get this from your Google Analytics 4 property
- Format:
G-XXXXXXXXXX(where X is your tracking ID)
NEXT_PUBLIC_ADSENSE_CLIENT_ID=ca-pub-xxxxxxxxxx
NEXT_PUBLIC_ADSENSE_SLOT_TOP=1234567890
NEXT_PUBLIC_ADSENSE_SLOT_BOTTOM=1234567891
NEXT_PUBLIC_ADSENSE_SLOT_LEFT=1234567892
NEXT_PUBLIC_ADSENSE_SLOT_RIGHT=1234567893NEXT_PUBLIC_ADSENSE_CLIENT_ID: Your AdSense publisher ID (format:ca-pub-xxxxxxxxxx)NEXT_PUBLIC_ADSENSE_SLOT_*: Individual ad slot IDs for each position
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION=your-google-verification-code- Get this from Google Search Console for site verification
NEXT_PUBLIC_SITE_URL=https://your-domain.com- Your actual domain URL for SEO and metadata
- Go to Google Analytics
- Create a new GA4 property or use existing one
- Go to Admin → Data Streams → Web
- Copy the Measurement ID (starts with G-)
- Go to Google AdSense
- Create an account and get approved
- Go to Ads → By ad unit
- Create ad units for different positions
- Copy the Ad unit code and extract:
data-ad-clientvalue forNEXT_PUBLIC_ADSENSE_CLIENT_IDdata-ad-slotvalues for each position
- Go to Google Search Console
- Add your property
- Choose "HTML tag" verification method
- Copy the content value from the meta tag
# Google Analytics Configuration
NEXT_PUBLIC_GA_ID=G-ABC123DEF4
# Google AdSense Configuration
NEXT_PUBLIC_ADSENSE_CLIENT_ID=ca-pub-1234567890123456
NEXT_PUBLIC_ADSENSE_SLOT_TOP=1234567890
NEXT_PUBLIC_ADSENSE_SLOT_BOTTOM=1234567891
NEXT_PUBLIC_ADSENSE_SLOT_LEFT=1234567892
NEXT_PUBLIC_ADSENSE_SLOT_RIGHT=1234567893
# Google Search Console Verification
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION=abc123def456ghi789
# Site Configuration
NEXT_PUBLIC_SITE_URL=https://json-tools.example.com- Never commit
.env.local- It's already in.gitignore - Use
NEXT_PUBLIC_prefix - Required for client-side access in Next.js - Restart your development server after adding environment variables
- Test in production - Some features may not work in development mode
- If ads don't show: Check browser console for AdSense errors
- If analytics don't track: Verify the GA ID format and network requests
- If verification fails: Ensure the verification code is correct and site is accessible
- In development: Placeholder ads will show if no AdSense config
- In production: Real ads will display based on your configuration
- Analytics will work in both environments with proper configuration