Skip to content

Commit a82b604

Browse files
authored
feat: Add hubspot tracking on client page change (#1194)
I had to add a client module that exports a `onRouteDidUpdate` function
1 parent c731d90 commit a82b604

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clientModule.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// client module for callbacks on route change
2+
// see https://docusaurus.io/docs/advanced/client#client-module-lifecycles
3+
export function onRouteDidUpdate({ location, previousLocation }) {
4+
// Don't execute if we are still on the same page; the lifecycle may be fired
5+
// because the hash changes (e.g. when navigating between headings)
6+
if (location.pathname !== previousLocation?.pathname) {
7+
// hubspot tracking page view
8+
// eslint-disable-next-line no-underscore-dangle, no-multi-assign
9+
const _hsq = window._hsq = window._hsq || [];
10+
_hsq.push(['setPath', window.location.pathname]);
11+
_hsq.push(['trackPageView']);
12+
}
13+
}

docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,5 @@ module.exports = {
210210
'^/legal/*',
211211
],
212212
},
213+
clientModules: ['./clientModule.js'],
213214
};

0 commit comments

Comments
 (0)