diff --git a/packages/docusaurus-plugin-google-gtag/src/gtag.ts b/packages/docusaurus-plugin-google-gtag/src/gtag.ts index a6e82b419aa0..2122511126a8 100644 --- a/packages/docusaurus-plugin-google-gtag/src/gtag.ts +++ b/packages/docusaurus-plugin-google-gtag/src/gtag.ts @@ -16,10 +16,9 @@ const clientModule: ClientModule = { onRouteDidUpdate({location, previousLocation}) { if (previousLocation && location.pathname !== previousLocation.pathname) { // Normally, the document title is updated in the next tick due to how - // `react-helmet-async` updates it. - // We want to send to gtag the current document title so we use - // setTimeout to put the function on the callback stack to be executed - // on the next tick. + // `react-helmet-async` updates it. We want to send the current document's + // title to gtag instead of the old one's, so we use `setTimeout` to defer + // execution to the next tick. // See: https://github.com/facebook/docusaurus/issues/7420 setTimeout(() => { // Always refer to the variable on window in case it gets overridden