Skip to content

Commit

Permalink
TEST
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 1f6efc1 commit 4c5c56e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"prepare": "git config --local core.hooksPath .githooks/",
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"build": "DEPLOYMENT_ENV=prod docusaurus build",
"preview-build": "DEPLOYMENT_ENV=preview docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
Expand Down
27 changes: 24 additions & 3 deletions snowplow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import { newTracker, trackPageView } from "@snowplow/browser-tracker";

const isProduction = process.env.NODE_ENV === "production";
// We're using the custom env variable
// DEPLOYMENT_ENV = "prod" || "preview
// to decide when to set the tracker
// process.env.NODE_ENV is set via webpack from
// Docusaurus in the build process, so it will be
// "production" for every built.

// To enable (temporary) tracking on a preview branch for
// testing, you can add a condition to also add it for preview deployment
// by setting a variable checking for the ENV var:
// const isPreviewDeploy = process.env.DEPLOYMENT_ENV === "preview";
// and extending the conditions for `isProductionDeploy` to `isProductionDeploy || isPreviewDeploy`
// Please remember to remove it before merging to main!

const isProductionDeploy = process.env.DEPLOYMENT_ENV === "prod";
const isPreviewDeploy = process.env.DEPLOYMENT_ENV === "preview";

const trackerConfig = {
appId: "klaw-docs",
platform: "web",
Expand All @@ -24,15 +40,20 @@ function setupBrowserTracker() {
newTracker("at", "dc.aiven.io", trackerConfig);
}

if (isProduction && ExecutionEnvironment.canUseDOM) {
if (isPreviewDeploy) {
console.log("isPreviewDeploy");
}

if (isProductionDeploy && ExecutionEnvironment.canUseDOM) {
// only set tracker on prod
console.log("is prod deploy");
setupBrowserTracker();
}

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

0 comments on commit 4c5c56e

Please sign in to comment.