Skip to content

feat: replace gtag with google-tag-manager plugin for GTM support#11709

Open
ceasermikes002 wants to merge 1 commit intofacebook:mainfrom
ceasermikes002:feat/gtm-support
Open

feat: replace gtag with google-tag-manager plugin for GTM support#11709
ceasermikes002 wants to merge 1 commit intofacebook:mainfrom
ceasermikes002:feat/gtm-support

Conversation

@ceasermikes002
Copy link

@ceasermikes002 ceasermikes002 commented Feb 3, 2026

Pre-flight checklist

  • I have read the Contributing Guidelines.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes Make gtag compliant with GDPR #2407) and the maintainers have approved on my working plan.

Motivation

This PR resolves issue #2407 regarding GTM support and GDPR compliance.

Previously, the Docusaurus website used the gtag option in @docusaurus/preset-classic, which only supports Google Analytics 4 (GA4) via plugin-google-gtag. This configuration does not support Google Tag Manager (GTM) container IDs (GTM-XXXXXXX), which are essential for implementing GDPR-compliant consent management (e.g., controlling when tags fire based on user consent).

This change:

  1. Disables the gtag configuration in preset-classic to prevent double-firing or conflicts.
  2. Adds the official @docusaurus/plugin-google-tag-manager to the website configuration.
  3. Configures it with a placeholder Container ID (GTM-XXXXXXX) to demonstrate the correct setup pattern.

This allows the Docusaurus website (and users copying this pattern) to leverage GTM for advanced tag management and consent enforcement.

Test Plan

I verified these changes by building the website locally and inspecting the generated HTML.

Steps to verify:

  1. Run yarn workspace website build.
  2. Inspect website/build/index.html.

Verification Results:

  • GTM Script Present: The gtm.js script injection logic is present in the <head>.
  • NoScript Fallback: The <noscript> iframe for GTM is correctly injected at the start of the <body>.
  • Correct ID: The configured ID GTM-XXXXXXX is present in the generated code.
  • No Duplicate gtag: Confirmed that the old gtag script is no longer being injected by the preset.

Related issues/PRs

Closes #2407

@meta-cla
Copy link

meta-cla bot commented Feb 3, 2026

Hi @ceasermikes002!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@netlify
Copy link

netlify bot commented Feb 3, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 90323ee
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/698206a598e9b500078f7d3b
😎 Deploy Preview https://deploy-preview-11709--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Feb 3, 2026
@meta-cla
Copy link

meta-cla bot commented Feb 3, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@ceasermikes002
Copy link
Author

@Josh-Cena

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make gtag compliant with GDPR

1 participant