Google Analytics Integration
Add Google Analytics 4 (GA4) to your documentation site. Requires a measurement ID starting with G-.
Add Google Analytics 4 to your documentation site to understand how users interact with your content.
Google Analytics integration works with GA4 (Google Analytics 4) measurement IDs that start with G-.
Getting Your Measurement ID
- Go to Google Analytics
- Select your property (or create one)
- Go to Admin → Data Streams
- Select your web stream (or create one)
- Copy the Measurement ID (starts with
G-)
Adding GA4 to Your Docs
Add the measurement ID to your docs.json:
{
"name": "My Docs",
"integrations": {
"ga4": {
"measurementId": "G-XXXXXXXXXX"
}
}
}
Replace G-XXXXXXXXXX with your actual measurement ID.
Viewing Your Data
After adding the integration:
- Trigger a rebuild of your docs
- Visit your live documentation site
- In Google Analytics, go to Reports → Real-time
- You should see your visit appear within 30 seconds
It can take 24-48 hours for data to appear in standard reports. Use Real-time reports for immediate verification.
Using with Google Tag Manager
If you're already using Google Tag Manager, you can configure GA4 through GTM instead of adding it directly. See Google Tag Manager Integration for details.
Don't add the same GA4 property both directly in docs.json and through Google Tag Manager—this will cause duplicate tracking.
Privacy Considerations
Google Analytics collects visitor data. Consider:
- Adding a cookie consent banner if required by GDPR/CCPA
- Updating your privacy policy to mention analytics
- Using IP anonymization if needed
Troubleshooting
- Verify your measurement ID - It must start with
G- - Check for ad blockers - They may block analytics scripts
- Wait for rebuild - Changes require a new build to take effect
- Use Real-time reports - Standard reports have a 24-48 hour delay
The ID must:
- Start with
G- - Contain only letters and numbers after
G- - Be copied exactly from Google Analytics (no extra spaces)
