Jamdesk Documentation logo

Google Tag Manager Integration

Add a GTM container ID to docs.json to load Google Tag Manager, with its analytics and tracking tags, on every page.

Add your GTM container ID to docs.json to load Google Tag Manager on every page of your documentation site. Your marketing team then sets up analytics, conversion pixels, and event tracking in GTM.

GTM container IDs start with GTM-. For Google Analytics alone, 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: 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

  1. Go to Google Tag Manager
  2. Select your account and container (or create new ones)
  3. 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:

docs.json
{
  "name": "My Docs",
  "integrations": {
    "gtm": {
      "tagId": "GTM-XXXXXXX"
    }
  }
}

Replace GTM-XXXXXXX with your container ID.

Set up cookie consent banners yourself if you need them. Jamdesk loads your GTM container on every page. Every tag you configure fires for every visitor. If GDPR, CCPA, or similar regulations apply to your readers, configure consent mode in GTM or use a consent management platform. Jamdesk can also gate GTM itself behind consent. See Cookie Consent.

Setting Up GA4 Through GTM

Load GA4 through GTM instead of adding it directly:

  1. In GTM, go to Tags → New
  2. Choose Google Analytics: GA4 Configuration
  3. Enter your GA4 Measurement ID (starts with G-)
  4. Set trigger to All Pages
  5. 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

  1. In GTM, click Preview in the top right
  2. Enter your documentation site URL
  3. A debug window shows which tags fire on each page

Using Browser Developer Tools

  1. Open your site with Developer Tools (F12)
  2. Go to Network tab
  3. Filter for gtm.js or googletagmanager
  4. Confirm the requests appear

Common GTM Tags for Docs

Track clicks on external links with this tag:

  1. Tag: Google Analytics: GA4 Event
  2. Event Name: click
  3. Trigger: Click - Just Links, where Click URL doesn't contain your domain

Track Search Usage

Track search use:

  1. Tag: Google Analytics: GA4 Event
  2. Event Name: search
  3. Trigger: Custom event matching your search interaction

Track Time on Page

Measure how long readers stay on a page:

  1. Tag: Google Analytics: GA4 Event
  2. Event Name: timing
  3. Trigger: Timer trigger (e.g., every 30 seconds)

Troubleshooting

  1. Check container ID: it must start with GTM-
  2. Publish your container: unpublished changes won't appear on your site
  3. Use Preview mode: GTM's preview shows which tags fire on each page

GA4 set up in two places counts every page view twice:

  • Directly in docs.json (integrations.ga4)
  • Through GTM as a GA4 tag

Remove one of them.

Google Analytics

Add GA4 directly without GTM

Project Analytics

View built-in Jamdesk analytics