Skip to content

fix: load gtag only in the production build - #3626

Merged
Chasen-Zhang merged 1 commit into
mainfrom
fix-gtag-dev-only
Nov 18, 2026
Merged

Chasen-Zhang merged 1 commit into
mainfrom
fix-gtag-dev-only

Conversation

@Chasen-Zhang

Copy link
Copy Markdown
Member

Summary

The docs dev server shows the error overlay "window.gtag is not a function" in some test environments.

Cause

  • The client module of @docusaurus/plugin-google-gtag calls window.gtag(...) on every route change.
  • The plugin turns itself on whenever NODE_ENV=production.
  • When the site runs under the dev server with NODE_ENV=production but without the gtag script on the page, every navigation throws.

Fix

docusaurus.config.ts now configures gtag only when site_env=production, and passes undefined otherwise, so the plugin is not loaded.

  • build:en and build:cn set site_env=production, so production analytics are unchanged.
  • start:en, start:cn and dev set site_env=development, so they no longer load gtag.

Testing

Not reproduced locally. To verify, restart the test environment from this branch and navigate between pages; the overlay should no longer appear.

Outside the production build, the gtag client module can run without
window.gtag and throws "window.gtag is not a function" on every route
change, as in the dev server overlay. Enable gtag only when
site_env=production, which build:en and build:cn set.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 18, 2026 3:47am UTC
docs-cn Ready Ready Preview Nov 18, 2026 3:47am UTC

Request Review

@Chasen-Zhang
Chasen-Zhang merged commit ca7b75a into main Nov 18, 2026
5 checks passed
@Chasen-Zhang
Chasen-Zhang deleted the fix-gtag-dev-only branch November 18, 2026 04:00

This branch was successfully deployed

2 active deployments
Preview – docs-cn — a6b796db Deployed Nov 18, 2026 by vercel[bot]
Preview – docs — a6b796db Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant