diff --git a/v2/docusaurus.config.js b/v2/docusaurus.config.js index 17ee3700f..8fa95269f 100644 --- a/v2/docusaurus.config.js +++ b/v2/docusaurus.config.js @@ -409,4 +409,8 @@ module.exports = { }, ] ], + clientModules:[ + //used to intercept client side navigation and fire analytics events. + require.resolve("./src/plugins/locationInterceptor") + ] }; diff --git a/v2/src/plugins/locationInterceptor.js b/v2/src/plugins/locationInterceptor.js new file mode 100644 index 000000000..07940d73c --- /dev/null +++ b/v2/src/plugins/locationInterceptor.js @@ -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(); + } + } + }; +})();