Skip to content

Commit

Permalink
Update comment for gtag plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-shalom authored May 15, 2022
1 parent e01d187 commit 563f4ea
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/docusaurus-plugin-google-gtag/src/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ const {trackingID} = globalData['docusaurus-plugin-google-gtag']!
const clientModule: ClientModule = {
onRouteDidUpdate({location, previousLocation}) {
if (previousLocation && location.pathname !== previousLocation.pathname) {
// Always refer to the variable on window in case it gets overridden
// elsewhere.
// 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.
// See: https://github.com/facebook/docusaurus/issues/7420
setTimeout(() => {
// Always refer to the variable on window in case it gets overridden
// elsewhere.
window.gtag('config', trackingID, {
page_path: location.pathname,
page_title: document.title,
Expand Down

0 comments on commit 563f4ea

Please sign in to comment.