diff --git a/clientModule.js b/clientModule.js new file mode 100644 index 000000000..43d04a081 --- /dev/null +++ b/clientModule.js @@ -0,0 +1,13 @@ +// client module for callbacks on route change +// see https://docusaurus.io/docs/advanced/client#client-module-lifecycles +export function onRouteDidUpdate({ location, previousLocation }) { + // Don't execute if we are still on the same page; the lifecycle may be fired + // because the hash changes (e.g. when navigating between headings) + if (location.pathname !== previousLocation?.pathname) { + // hubspot tracking page view + // eslint-disable-next-line no-underscore-dangle, no-multi-assign + const _hsq = window._hsq = window._hsq || []; + _hsq.push(['setPath', window.location.pathname]); + _hsq.push(['trackPageView']); + } +} diff --git a/docusaurus.config.js b/docusaurus.config.js index be899e25d..1e2ebb18f 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -210,4 +210,5 @@ module.exports = { '^/legal/*', ], }, + clientModules: ['./clientModule.js'], };