From 4c5c56e4259c02ebb62e5420eefe95400b3a0a36 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Wed, 1 Nov 2023 10:56:40 +0100 Subject: [PATCH] TEST Signed-off-by: Mirjam Aulbach --- package.json | 3 ++- snowplow.js | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e5196f35..ef096815 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/snowplow.js b/snowplow.js index 57feef2e..4546db8d 100644 --- a/snowplow.js +++ b/snowplow.js @@ -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", @@ -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