Skip to content

Commit

Permalink
feat: Add hubspot tracking on client page change (#1194)
Browse files Browse the repository at this point in the history
I had to add a client module that exports a `onRouteDidUpdate` function
  • Loading branch information
webrdaniel authored Sep 10, 2024
1 parent c731d90 commit a82b604
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clientModule.js
Original file line number Diff line number Diff line change
@@ -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']);
}
}
1 change: 1 addition & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,5 @@ module.exports = {
'^/legal/*',
],
},
clientModules: ['./clientModule.js'],
};

0 comments on commit a82b604

Please sign in to comment.