-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add hubspot tracking on client page change (#1194)
I had to add a client module that exports a `onRouteDidUpdate` function
- Loading branch information
1 parent
c731d90
commit a82b604
Showing
2 changed files
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,4 +210,5 @@ module.exports = { | |
'^/legal/*', | ||
], | ||
}, | ||
clientModules: ['./clientModule.js'], | ||
}; |