Skip to content

Commit

Permalink
Merge pull request #731 from supertokens/fix/analytics
Browse files Browse the repository at this point in the history
feat: intercept client-side navigation.
  • Loading branch information
rishabhpoddar authored Oct 20, 2023
2 parents 2020fb6 + 97885dd commit a015868
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions v2/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,8 @@ module.exports = {
},
]
],
clientModules:[
//used to intercept client side navigation and fire analytics events.
require.resolve("./src/plugins/locationInterceptor")
]
};
17 changes: 17 additions & 0 deletions v2/src/plugins/locationInterceptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";

export default (function() {
if (!ExecutionEnvironment.canUseDOM) {
return null;
}

return {
onRouteUpdate() {
if (window.stAnalytics) {
const analytics = window.stAnalytics.getInstance();
analytics.sendPageViewEvents();
analytics.sendPageViewEventToSegment();
}
}
};
})();

0 comments on commit a015868

Please sign in to comment.