From 6db303fca70ac854f4b9a4da73a7579f715f29ec Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:20:40 +0100 Subject: [PATCH] fix: analytics bug Workaround for https://github.com/facebook/docusaurus/issues/3399 Closes https://github.com/ory-corp/general/issues/482 --- src/plugins/analytics/analytics.js | 8 ++++++++ src/plugins/docusaurus-plugin-matamo/analytics.js | 1 + 2 files changed, 9 insertions(+) diff --git a/src/plugins/analytics/analytics.js b/src/plugins/analytics/analytics.js index 1f1ed24ed..2e787f865 100644 --- a/src/plugins/analytics/analytics.js +++ b/src/plugins/analytics/analytics.js @@ -12,6 +12,8 @@ export default (function () { return null } + // Workaround until https://github.com/facebook/docusaurus/issues/3399 is fixed + let lastLocation = window.location.pathname return { onRouteUpdate({ location }) { if (typeof window.gtag !== 'function') { @@ -21,6 +23,12 @@ export default (function () { const pagePath = location ? location.pathname + location.search + location.hash : undefined + + if (lastLocation === location.pathname) { + return + } + lastLocation = location.pathname + window.gtag('config', 'UA-71865250-1', { page_path: pagePath }) diff --git a/src/plugins/docusaurus-plugin-matamo/analytics.js b/src/plugins/docusaurus-plugin-matamo/analytics.js index e0dc03963..d446b8981 100644 --- a/src/plugins/docusaurus-plugin-matamo/analytics.js +++ b/src/plugins/docusaurus-plugin-matamo/analytics.js @@ -12,6 +12,7 @@ export default (function () { return null } + // Workaround until https://github.com/facebook/docusaurus/issues/3399 is fixed let lastLocation = window.location.pathname return { onRouteUpdate({ location }) {