From f4dcbf2cfa100278cabbecb07bebb0259c7f556e Mon Sep 17 00:00:00 2001 From: Andras Eszes Date: Fri, 15 Nov 2024 16:16:11 +0100 Subject: [PATCH] feat: add Clarity to the WFE (#1305) --- package.json | 2 +- rails/transformer.rb | 4 ++-- source/index.slim | 4 ++-- source/javascripts/clarity.js | 5 +++++ source/javascripts/hotjar.js | 14 -------------- webpack.config.js | 8 ++++---- 6 files changed, 14 insertions(+), 23 deletions(-) create mode 100644 source/javascripts/clarity.js delete mode 100644 source/javascripts/hotjar.js diff --git a/package.json b/package.json index 828af7c31..659d21fd8 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "lint": "eslint source/javascripts --cache", "lint:fix": "eslint source/javascripts --cache --quiet --fix", "build": "webpack --bail", - "build:website": "MODE=WEBSITE ANALYTICS=true HOTJAR=true DATADOG_RUM=true npm run build", + "build:website": "MODE=WEBSITE ANALYTICS=true CLARITY=true DATADOG_RUM=true npm run build", "build:plugin": "MODE=CLI ANALYTICS=true npm run build && ./_scripts/compile_api.sh", "start:dev": "webpack-dev-server", "start:base": "concurrently \"npm:start:dev\" \"DEV=true ./_scripts/run_api.sh 4000\"", diff --git a/rails/transformer.rb b/rails/transformer.rb index 117de6cb1..e1574c6c5 100644 --- a/rails/transformer.rb +++ b/rails/transformer.rb @@ -68,8 +68,8 @@ def analytics? ENV['ANALYTICS'] == 'true' end -def hotjar? - ENV['HOTJAR'] == 'true' +def clarity? + ENV['CLARITY'] == 'true' end def freshpaint? diff --git a/source/index.slim b/source/index.slim index 029b96964..31bf56505 100644 --- a/source/index.slim +++ b/source/index.slim @@ -9,8 +9,8 @@ html script[src="#{ mode_dependant_asset_path 'javascripts/vendor.js' }"] script[src="#{ mode_dependant_asset_path 'javascripts/strings.js' }"] script[src="#{ mode_dependant_asset_path 'javascripts/routes.js' }"] - - if hotjar? - script[src="#{ mode_dependant_asset_path 'javascripts/hotjar.js' }"] + - if clarity? + script[src="#{ mode_dependant_asset_path 'javascripts/clarity.js' }"] - if datadog_rum? script[src="#{ mode_dependant_asset_path 'javascripts/datadogrum.js' }"] script[src="#{ mode_dependant_asset_path 'javascripts/main.js' }"] diff --git a/source/javascripts/clarity.js b/source/javascripts/clarity.js new file mode 100644 index 000000000..b38f8842c --- /dev/null +++ b/source/javascripts/clarity.js @@ -0,0 +1,5 @@ +(function (c, l, a, r, i, t, y) { + c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) }; + t = l.createElement(r); t.async = 1; t.src = "https://www.clarity.ms/tag/" + i; + y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y); +})(window, document, "clarity", "script", "mxdzahxph2"); diff --git a/source/javascripts/hotjar.js b/source/javascripts/hotjar.js deleted file mode 100644 index d076d4a2f..000000000 --- a/source/javascripts/hotjar.js +++ /dev/null @@ -1,14 +0,0 @@ -// Hotjar Tracking Code for https://www.bitrise.io -(function(h, o, t, j, a, r) { - h.hj = - h.hj || - function() { - (h.hj.q = h.hj.q || []).push(arguments); - }; - h._hjSettings = { hjid: 236822, hjsv: 6 }; - a = o.getElementsByTagName("head")[0]; - r = o.createElement("script"); - r.async = 1; - r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv; - a.appendChild(r); -})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv="); \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 0773b6e8c..0b53ac5b8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -62,11 +62,11 @@ const MonacoPluginOptions = { ], }; -const { NODE_ENV, MODE, PUBLIC_URL_ROOT, HOTJAR, DEV_SERVER_PORT, DATADOG_RUM } = process.env; +const { NODE_ENV, MODE, PUBLIC_URL_ROOT, CLARITY, DEV_SERVER_PORT, DATADOG_RUM } = process.env; const isProd = NODE_ENV === 'prod'; const isWebsiteMode = MODE === 'WEBSITE'; const urlPrefix = isWebsiteMode ? PUBLIC_URL_ROOT : ''; -const isHotjarEnabled = HOTJAR === 'true'; +const isClarityEnabled = CLARITY === 'true'; const isDataDogRumEnabled = DATADOG_RUM === 'true'; const publicPath = `${urlPrefix}/${version}/`; @@ -93,8 +93,8 @@ const entry = { routes: './javascripts/routes.js.erb', main: './javascripts/index.js', }; -if (isHotjarEnabled) { - entry.hotjar = './javascripts/hotjar.js'; +if (isClarityEnabled) { + entry.clarity = './javascripts/clarity.js'; } if (isDataDogRumEnabled) { entry.datadogrum = './javascripts/datadog-rum.js.erb';