Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit dcf912c

Browse files
committed
fix(analytics): manually trigger hubspot and segment tracking
1 parent c1bebc5 commit dcf912c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

docusaurus.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = {
9696
],
9797
],
9898
plugins: [
99+
"./plugins/analytics",
99100
[
100101
"@docusaurus/plugin-client-redirects",
101102
{

plugins/analytics/analytics.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
onRouteDidUpdate({ location, previousLocation }) {
3+
if (
4+
previousLocation &&
5+
(location.pathname !== previousLocation.pathname ||
6+
location.search !== previousLocation.search ||
7+
location.hash !== previousLocation.hash)
8+
) {
9+
//segment
10+
window.analytics?.page(location.pathname, { url: location.pathname });
11+
// hubspot
12+
window._hsq?.push(["setPath", location.pathname]);
13+
window._hsq?.push(["trackPageView"]);
14+
}
15+
},
16+
};

plugins/analytics/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = function () {
2+
return {
3+
name: "docusaurus-plugin-analytics",
4+
getClientModules() {
5+
return ["./analytics"];
6+
},
7+
};
8+
};

0 commit comments

Comments
 (0)