Skip to content

Commit

Permalink
Update snowplow config (#153)
Browse files Browse the repository at this point in the history
* Update snowplow config to work with docusaurus routing.
* Add correct prop-type
* Don't set tracker on dev env.

---------

Signed-off-by: Mirjam Aulbach <[email protected]>
  • Loading branch information
programmiri authored Nov 1, 2023
1 parent d78784e commit 8bad411
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const config = {
onBrokenMarkdownLinks: "warn",

clientModules: [require.resolve("./snowplow.js")],

// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang. For example, if your site is Chinese, you may want
// to replace "en" with "zh-Hans".
Expand Down
22 changes: 19 additions & 3 deletions snowplow.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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",
forceSecureTracker: true,
discoverRootDomain: true,
cookieSameSite: "Lax",
anonymousTracking: { withServerAnonymisation: true },
postPath: "/aiven/dc",
postPath: "/aiven/dc2",
crossDomainLinker: function (linkElement) {
return linkElement.id === "crossDomainLink";
},
Expand All @@ -23,9 +24,24 @@ function setupBrowserTracker() {
newTracker("at", "dc.aiven.io", trackerConfig);
}

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

const module = {
onRouteDidUpdate({ location, previousLocation }) {
// 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();
});
}
}
},
};

export default module;
2 changes: 1 addition & 1 deletion src/components/HomepageFeatures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Feature({ Svg, title, description }) {
Feature.propTypes = {
Svg: PropTypes.any,
title: PropTypes.string,
description: PropTypes.string,
description: PropTypes.node,
};

export default function HomepageFeatures() {
Expand Down

0 comments on commit 8bad411

Please sign in to comment.