Google Tag Manager Integration
Add your GTM container ID to docs.json to load Google Tag Manager on every page. Manage analytics and tracking tags from GTM.
Add your GTM container ID to docs.json to load Google Tag Manager on every page of your documentation site. From there, your marketing team can configure analytics, conversion pixels, and event tracking entirely within GTM.
GTM container IDs start with GTM-. If you just need Google Analytics, see Google Analytics Integration for a simpler setup.
When to Use GTM
Use Google Tag Manager when you need:
- Multiple tracking tools - GA4, Facebook Pixel, LinkedIn, etc.
- Marketing team control - Let marketers add tags without developer help
- Advanced triggers - Track button clicks, form submissions, video views
- A/B testing integration - Connect tools like Google Optimize
For basic analytics only, adding GA4 directly is simpler.
Getting Your Container ID
- Go to Google Tag Manager
- Select your account and container (or create new ones)
- Copy the Container ID from the top of the page (starts with
GTM-)
Adding GTM to Your Docs
Add the container ID to your docs.json:
{
"name": "My Docs",
"integrations": {
"gtm": {
"tagId": "GTM-XXXXXXX"
}
}
}
Replace GTM-XXXXXXX with your actual container ID.
Setting Up GA4 Through GTM
If you want to use GA4 through GTM instead of adding it directly:
- In GTM, go to Tags → New
- Choose Google Analytics: GA4 Configuration
- Enter your GA4 Measurement ID (starts with
G-) - Set trigger to All Pages
- Publish your container
If you configure GA4 through GTM, don't also add it directly in docs.json. This causes duplicate tracking.
Verifying the Installation
Using GTM Preview Mode
- In GTM, click Preview in the top right
- Enter your documentation site URL
- A debug window shows which tags fire on each page
Using Browser Developer Tools
- Open your site with Developer Tools (F12)
- Go to Network tab
- Filter for
gtm.jsorgoogletagmanager - You should see requests being made
Common GTM Tags for Docs
Track Outbound Links
Create a tag to track when users click external links:
- Tag: Google Analytics: GA4 Event
- Event Name:
click - Trigger: Click - Just Links, where Click URL doesn't contain your domain
Track Search Usage
Track when users interact with the search feature:
- Tag: Google Analytics: GA4 Event
- Event Name:
search - Trigger: Custom event matching your search interaction
Track Time on Page
Understand how long users spend reading:
- Tag: Google Analytics: GA4 Event
- Event Name:
timing - Trigger: Timer trigger (e.g., every 30 seconds)
Troubleshooting
- Check container ID - Must start with
GTM- - Publish your container - Unpublished changes won't appear on your site
- Use Preview mode - GTM's preview shows which tags fire on each page
If you have GA4 configured both:
- Directly in
docs.json(integrations.ga4) - Through GTM as a GA4 tag
You'll get duplicate page views. Remove one of them.
