Skip to content

Commit

Permalink
Don't set tracker on dev env.
Browse files Browse the repository at this point in the history
Signed-off-by: Mirjam Aulbach <[email protected]>
  • Loading branch information
programmiri committed Nov 1, 2023
1 parent c42ad26 commit 1f6efc1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions snowplow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import { newTracker, trackPageView } from "@snowplow/browser-tracker";

const isProduction = process.env.NODE_ENV === "production";
const trackerConfig = {
appId: "klaw-docs",
platform: "web",
Expand All @@ -23,17 +24,22 @@ function setupBrowserTracker() {
newTracker("at", "dc.aiven.io", trackerConfig);
}

if (ExecutionEnvironment.canUseDOM) {
if (isProduction && ExecutionEnvironment.canUseDOM) {
// only set tracker on prod
setupBrowserTracker();
}

const module = {
onRouteDidUpdate({ location, previousLocation }) {
if (location.pathname !== previousLocation?.pathname) {
// see https://github.com/facebook/docusaurus/pull/7424 regarding setTimeout
setTimeout(() => {
trackPageView();
});
// only set tracker on prod
if (isProduction) {
// only call trackPageView when page route changed
if (location.pathname !== previousLocation?.pathname) {
// see https://github.com/facebook/docusaurus/pull/7424 regarding setTimeout
setTimeout(() => {
trackPageView();
});
}
}
},
};
Expand Down

0 comments on commit 1f6efc1

Please sign in to comment.