{"record":{"id":"7d5ef3caff50d5dd","repo":"facebook/docusaurus","slug":"in-docusaurus-v4-the-google-analytics-plugin-has","errorCode":null,"errorMessage":"In Docusaurus v4, the Google Analytics plugin has been removed.\nYou can now use either:\n- @docusaurus/plugin-google-gtag - presetOptions.gtag\n- @docusaurus/plugin-google-tag-manager - presetOptions.googleTagManager\n\nSee also: https://github.com/facebook/docusaurus/issues/7221","messagePattern":"In Docusaurus v4, the Google Analytics plugin has been removed\\.\nYou can now use either:\n- @docusaurus/plugin-google-gtag - presetOptions\\.gtag\n- @docusaurus/plugin-google-tag-manager - presetOptions\\.googleTagManager\n\nSee also: https://github\\.com/facebook/docusaurus/issues/7221","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-preset-classic/src/index.ts","lineNumber":60,"sourceCode":"    gtag,\n    googleTagManager,\n    ...rest\n  } = opts;\n\n  const themes: PluginConfig[] = [];\n  themes.push(makePluginConfig('@docusaurus/theme-classic', theme));\n  if (algolia) {\n    themes.push(require.resolve('@docusaurus/theme-search-algolia'));\n  }\n  if ('gtag' in themeConfig) {\n    throw new Error(\n      'The \"gtag\" field in themeConfig should now be specified as option for plugin-google-gtag. For preset-classic, simply move themeConfig.gtag to preset options. More information at https://github.com/facebook/docusaurus/pull/5832.',\n    );\n  }\n\n  // TODO Docusaurus v5: remove\n  if ('googleAnalytics' in opts || 'googleAnalytics' in themeConfig) {\n    throw new Error(\n      `In Docusaurus v4, the Google Analytics plugin has been removed.\nYou can now use either:\n- @docusaurus/plugin-google-gtag - presetOptions.gtag\n- @docusaurus/plugin-google-tag-manager - presetOptions.googleTagManager\n\nSee also: https://github.com/facebook/docusaurus/issues/7221`,\n    );\n  }\n\n  const plugins: PluginConfig[] = [];\n\n  // TODO Docusaurus v4: temporary due to the opt-in flag\n  // In v4 we'd like to use layers everywhere natively\n  if (siteConfig.future.v4.useCssCascadeLayers) {\n    plugins.push(makePluginConfig('@docusaurus/plugin-css-cascade-layers'));\n  }\n\n  if (docs !== false) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-preset-classic/src/index.ts#L42-L78","documentation":"Thrown by preset-classic when a 'googleAnalytics' key is present in either the preset options or themeConfig. The standalone Google Analytics plugin was removed in Docusaurus v4; users must migrate to plugin-google-gtag (gtag) or plugin-google-tag-manager (googleTagManager). Marked TODO for removal in v5, this is the v4 deprecation enforcement.","triggerScenarios":"Carrying over themeConfig.googleAnalytics or preset option googleAnalytics from a v3 (or earlier) config after upgrading to v4.","commonSituations":"Running the v3->v4 upgrade without migrating analytics; copying a v3 docusaurus.config; using a starter template that still references googleAnalytics.","solutions":["Replace googleAnalytics with gtag (recommended for GA4) under preset options: presets: [['classic', { gtag: { trackingID: 'G-XXX' } }]].","Or use googleTagManager if you rely on GTM: presets: [['classic', { googleTagManager: { containerId: 'GTM-XXX' } }]].","Remove the googleAnalytics key from both preset options and themeConfig; rebuild."],"exampleFix":"// before\npresets: [['classic', { googleAnalytics: { trackingID: 'UA-XXX' } }]]\n// after\npresets: [['classic', { gtag: { trackingID: 'G-XXX' } }]]","handlingStrategy":"validation","validationCode":"const hasGA = 'googleAnalytics' in (presetOptions ?? {}) || 'googleAnalytics' in (siteConfig.themeConfig ?? {});\nif (hasGA) throw new Error('googleAnalytics removed in v4; use gtag or googleTagManager');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When upgrading to v4, migrate analytics as part of the upgrade checklist.","Prefer GA4 gtag over the legacy googleAnalytics key."],"tags":["analytics","preset-classic","migration","v4"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}