From 2348d20337f2138ba8bd8c538cbc2abb77633036 Mon Sep 17 00:00:00 2001 From: Sukanya Rath Date: Wed, 1 May 2024 14:25:16 -0700 Subject: [PATCH 1/9] fix(frontend): snowplow environment specific URL setting through Caddyfile. Signed-off-by: Sukanya Rath --- .../charts/frontend/templates/deployment.yaml | 2 ++ charts/fin-pay-transparency/values-prod.yaml | 1 + charts/fin-pay-transparency/values.yaml | 1 + frontend/.gitignore | 3 ++- frontend/Caddyfile | 25 +++++++++++++++++++ frontend/public/snowplow.js | 20 --------------- 6 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 frontend/public/snowplow.js diff --git a/charts/fin-pay-transparency/charts/frontend/templates/deployment.yaml b/charts/fin-pay-transparency/charts/frontend/templates/deployment.yaml index 7a7a8baa9..f9526009b 100644 --- a/charts/fin-pay-transparency/charts/frontend/templates/deployment.yaml +++ b/charts/fin-pay-transparency/charts/frontend/templates/deployment.yaml @@ -45,6 +45,8 @@ spec: value: http://{{ .Release.Name }}-backend - name: LOG_LEVEL value: {{ .Values.env.logLevel }} + - name: SNOWPLOW_URL + value: {{ .Values.env.snowplowUrl }} ports: - name: http containerPort: {{ .Values.service.targetPort }} diff --git a/charts/fin-pay-transparency/values-prod.yaml b/charts/fin-pay-transparency/values-prod.yaml index 8f22aaff3..a47c4ab96 100644 --- a/charts/fin-pay-transparency/values-prod.yaml +++ b/charts/fin-pay-transparency/values-prod.yaml @@ -124,6 +124,7 @@ frontend: memory: 50Mi env: logLevel: info + snowplowUrl: spt.apps.gov.bc.ca autoscaling: enabled: true minReplicas: 3 diff --git a/charts/fin-pay-transparency/values.yaml b/charts/fin-pay-transparency/values.yaml index 808d42654..67bcd08b5 100644 --- a/charts/fin-pay-transparency/values.yaml +++ b/charts/fin-pay-transparency/values.yaml @@ -124,6 +124,7 @@ frontend: memory: 50Mi env: logLevel: info + snowplowUrl: spm.apps.gov.bc.ca autoscaling: enabled: true minReplicas: 3 diff --git a/frontend/.gitignore b/frontend/.gitignore index b22e2b50f..9fabcd7ff 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -26,4 +26,5 @@ local.* /blob-report/ /playwright/ .env.playwright -user.json \ No newline at end of file +user.json +public/snowplow.js diff --git a/frontend/Caddyfile b/frontend/Caddyfile index 7f5a3ce56..d570cb98f 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -14,6 +14,31 @@ } level {$LOG_LEVEL} } + handle /snowplow.js { + header { + Content-Type text/javascript + } + respond `// + ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; + p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) + };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; + n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); + window.snowplow('newTracker','rt','{$SNOWPLOW_URL}', { + appId: 'Snowplow_standalone', + cookieLifetime: 86400 * 548, + platform: 'web', + post: true, + forceSecureTracker: true, + contexts: { + webPage: true, + performanceTiming: true + } + }); + window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds + window.snowplow('enableLinkClickTracking'); + window.snowplow('trackPageView'); + // ` + } root * /app/dist encode zstd gzip file_server diff --git a/frontend/public/snowplow.js b/frontend/public/snowplow.js deleted file mode 100644 index 5c91b0b74..000000000 --- a/frontend/public/snowplow.js +++ /dev/null @@ -1,20 +0,0 @@ -// -;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; - p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) - };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; - n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); -window.snowplow('newTracker','rt','spm.apps.gov.bc.ca', { - appId: 'Snowplow_standalone', - cookieLifetime: 86400 * 548, - platform: 'web', - post: true, - forceSecureTracker: true, - contexts: { - webPage: true, - performanceTiming: true - } -}); -window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds -window.snowplow('enableLinkClickTracking'); -window.snowplow('trackPageView'); -// From 2c2480eafbb6209607ed6a95b4745caa6f80232f Mon Sep 17 00:00:00 2001 From: Sukanya Rath Date: Wed, 1 May 2024 14:36:03 -0700 Subject: [PATCH 2/9] fix CaddyFile Signed-off-by: Sukanya Rath --- frontend/Caddyfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/Caddyfile b/frontend/Caddyfile index d570cb98f..0dcdaf510 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -18,12 +18,12 @@ header { Content-Type text/javascript } - respond `// + respond "// ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; - n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); - window.snowplow('newTracker','rt','{$SNOWPLOW_URL}', { + n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,'script','https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js','snowplow')); + window.snowplow('newTracker','rt','{$SNOWPLOW_URL}', { appId: 'Snowplow_standalone', cookieLifetime: 86400 * 548, platform: 'web', @@ -37,7 +37,7 @@ window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds window.snowplow('enableLinkClickTracking'); window.snowplow('trackPageView'); - // ` + // " } root * /app/dist encode zstd gzip From 818749c50ef9ae824a7275deb56d3c69d3119ddd Mon Sep 17 00:00:00 2001 From: Sukanya Rath <98050194+sukanya-rath@users.noreply.github.com> Date: Wed, 1 May 2024 15:23:44 -0700 Subject: [PATCH 3/9] trying replace env var directly in js --- frontend/.gitignore | 1 - frontend/Caddyfile | 29 ++++------------------------- frontend/index.html | 2 +- frontend/public/snowplow.js | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 frontend/public/snowplow.js diff --git a/frontend/.gitignore b/frontend/.gitignore index 9fabcd7ff..463fbddbf 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -27,4 +27,3 @@ local.* /playwright/ .env.playwright user.json -public/snowplow.js diff --git a/frontend/Caddyfile b/frontend/Caddyfile index 0dcdaf510..ad715eafe 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -14,31 +14,10 @@ } level {$LOG_LEVEL} } - handle /snowplow.js { - header { - Content-Type text/javascript - } - respond "// - ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; - p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) - };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; - n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,'script','https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js','snowplow')); - window.snowplow('newTracker','rt','{$SNOWPLOW_URL}', { - appId: 'Snowplow_standalone', - cookieLifetime: 86400 * 548, - platform: 'web', - post: true, - forceSecureTracker: true, - contexts: { - webPage: true, - performanceTiming: true - } - }); - window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds - window.snowplow('enableLinkClickTracking'); - window.snowplow('trackPageView'); - // " - } + handle /env.js { + header Content-Type text/javascript + respond `window.config = {"SNOWPLOW_URL":"{$SNOWPLOW_URL}"};` + } root * /app/dist encode zstd gzip file_server diff --git a/frontend/index.html b/frontend/index.html index a4edea987..219fb2b38 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -17,7 +17,7 @@ - +
diff --git a/frontend/public/snowplow.js b/frontend/public/snowplow.js new file mode 100644 index 000000000..deda9df92 --- /dev/null +++ b/frontend/public/snowplow.js @@ -0,0 +1,20 @@ +// +;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; + p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) + };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; + n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); +window.snowplow('newTracker','rt', window.config.SNOWPLOW_URL, { + appId: 'Snowplow_standalone', + cookieLifetime: 86400 * 548, + platform: 'web', + post: true, + forceSecureTracker: true, + contexts: { + webPage: true, + performanceTiming: true + } +}); +window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds +window.snowplow('enableLinkClickTracking'); +window.snowplow('trackPageView'); +// \ No newline at end of file From e6244a326eb8dc093bcb2603d52638fefec007ad Mon Sep 17 00:00:00 2001 From: Sukanya Rath <98050194+sukanya-rath@users.noreply.github.com> Date: Wed, 1 May 2024 15:40:58 -0700 Subject: [PATCH 4/9] move script from body to head --- frontend/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/index.html b/frontend/index.html index 219fb2b38..8b80732d8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,6 +10,7 @@ + FIN Pay Transparency @@ -17,7 +18,6 @@ -
From a7836be91d883b7d994ab001ca39308621e1ac92 Mon Sep 17 00:00:00 2001 From: Sukanya Rath <98050194+sukanya-rath@users.noreply.github.com> Date: Wed, 1 May 2024 15:51:19 -0700 Subject: [PATCH 5/9] adding proper header --- frontend/Caddyfile | 2 +- frontend/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/Caddyfile b/frontend/Caddyfile index ad715eafe..e03a806a4 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -15,7 +15,7 @@ level {$LOG_LEVEL} } handle /env.js { - header Content-Type text/javascript + header Content-Type "text/javascript" respond `window.config = {"SNOWPLOW_URL":"{$SNOWPLOW_URL}"};` } root * /app/dist diff --git a/frontend/index.html b/frontend/index.html index 8b80732d8..12e66a266 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,7 +10,7 @@ - + FIN Pay Transparency From f4220e6072e39da62b5d5b4db6d960f749b7501a Mon Sep 17 00:00:00 2001 From: Sukanya Rath <98050194+sukanya-rath@users.noreply.github.com> Date: Wed, 1 May 2024 16:22:54 -0700 Subject: [PATCH 6/9] fix caddyfile --- frontend/Caddyfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/Caddyfile b/frontend/Caddyfile index e03a806a4..e21ca253d 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -15,14 +15,16 @@ level {$LOG_LEVEL} } handle /env.js { - header Content-Type "text/javascript" + header { + Content-Type text/javascript + } respond `window.config = {"SNOWPLOW_URL":"{$SNOWPLOW_URL}"};` } root * /app/dist encode zstd gzip file_server @spa_router { - not path /api/* + not path /api/* /env.js file { try_files {path} /index.html } From f22044716b4889f2c4340f530148aba420abe15c Mon Sep 17 00:00:00 2001 From: goemen Date: Wed, 1 May 2024 16:28:12 -0700 Subject: [PATCH 7/9] add snowplow url at build time --- .github/workflows/ci_cd_on_pr_dev_sandbox.yml | 2 ++ frontend/Dockerfile | 3 ++- frontend/index.html | 1 - frontend/public/snowplow.js | 20 ----------------- frontend/src/main.js | 3 +++ frontend/src/snowplow.js | 22 +++++++++++++++++++ 6 files changed, 29 insertions(+), 22 deletions(-) delete mode 100644 frontend/public/snowplow.js create mode 100644 frontend/src/snowplow.js diff --git a/.github/workflows/ci_cd_on_pr_dev_sandbox.yml b/.github/workflows/ci_cd_on_pr_dev_sandbox.yml index 60a4e928f..0c6908a91 100644 --- a/.github/workflows/ci_cd_on_pr_dev_sandbox.yml +++ b/.github/workflows/ci_cd_on_pr_dev_sandbox.yml @@ -40,6 +40,8 @@ jobs: triggers: ('frontend/') build_file: ./frontend/Dockerfile build_context: ./frontend + build_args: | + VITE_SNOWPLOW_URL=${{ secrets.VITE_SNOWPLOW_URL }} - package: database-migrations triggers: ('backend/db') build_file: ./backend/db/Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 69f3370b5..c6ff08f3f 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,8 +1,9 @@ # Build static files FROM node:lts-alpine AS build - +ARG VITE_SNOWPLOW_URL WORKDIR /app COPY . . +ENV VITE_SNOWPLOW_URL=$VITE_SNOWPLOW_URL RUN npm ci --ignore-scripts && \ npm run build diff --git a/frontend/index.html b/frontend/index.html index 12e66a266..05b1a4236 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,7 +10,6 @@ - FIN Pay Transparency diff --git a/frontend/public/snowplow.js b/frontend/public/snowplow.js deleted file mode 100644 index deda9df92..000000000 --- a/frontend/public/snowplow.js +++ /dev/null @@ -1,20 +0,0 @@ -// -;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; - p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) - };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; - n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); -window.snowplow('newTracker','rt', window.config.SNOWPLOW_URL, { - appId: 'Snowplow_standalone', - cookieLifetime: 86400 * 548, - platform: 'web', - post: true, - forceSecureTracker: true, - contexts: { - webPage: true, - performanceTiming: true - } -}); -window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds -window.snowplow('enableLinkClickTracking'); -window.snowplow('trackPageView'); -// \ No newline at end of file diff --git a/frontend/src/main.js b/frontend/src/main.js index 869b55cfd..15d7014d6 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -18,6 +18,9 @@ import 'viewerjs/dist/viewer.css'; import component from 'v-viewer'; import VueDOMPurifyHTML from 'vue-dompurify-html'; +import { initializeSnowplow } from './snowplow'; +initializeSnowplow(import.meta.env.VITE_SNOWPLOW_URL); + const myCustomLightTheme = { dark: false, colors: { diff --git a/frontend/src/snowplow.js b/frontend/src/snowplow.js new file mode 100644 index 000000000..10bc97fce --- /dev/null +++ b/frontend/src/snowplow.js @@ -0,0 +1,22 @@ +// +export const initializeSnowplow = (url) => { + ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; + p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) + };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; + n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); + window.snowplow('newTracker','rt', url, { + appId: 'Snowplow_standalone', + cookieLifetime: 86400 * 548, + platform: 'web', + post: true, + forceSecureTracker: true, + contexts: { + webPage: true, + performanceTiming: true + } + }); + window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds + window.snowplow('enableLinkClickTracking'); + window.snowplow('trackPageView'); + // +} \ No newline at end of file From 2f290479d2063dc75747498d37d027bd5e1d684d Mon Sep 17 00:00:00 2001 From: goemen Date: Wed, 1 May 2024 16:33:18 -0700 Subject: [PATCH 8/9] ignore tests --- frontend/src/main.js | 1 + frontend/src/snowplow.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index 15d7014d6..70f7feb46 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -19,6 +19,7 @@ import component from 'v-viewer'; import VueDOMPurifyHTML from 'vue-dompurify-html'; import { initializeSnowplow } from './snowplow'; +/* istanbul ignore next */ initializeSnowplow(import.meta.env.VITE_SNOWPLOW_URL); const myCustomLightTheme = { diff --git a/frontend/src/snowplow.js b/frontend/src/snowplow.js index 10bc97fce..d06005cf0 100644 --- a/frontend/src/snowplow.js +++ b/frontend/src/snowplow.js @@ -1,10 +1,28 @@ // +/* istanbul ignore next */ export const initializeSnowplow = (url) => { - ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; - p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) - };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; - n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); - window.snowplow('newTracker','rt', url, { + (function (p, l, o, w, i, n, g) { + if (!p[i]) { + p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || []; + p.GlobalSnowplowNamespace.push(i); + p[i] = function () { + (p[i].q = p[i].q || []).push(arguments); + }; + p[i].q = p[i].q || []; + n = l.createElement(o); + g = l.getElementsByTagName(o)[0]; + n.async = 1; + n.src = w; + g.parentNode.insertBefore(n, g); + } + })( + window, + document, + 'script', + 'https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js', + 'snowplow', + ); + window.snowplow('newTracker', 'rt', url, { appId: 'Snowplow_standalone', cookieLifetime: 86400 * 548, platform: 'web', @@ -12,11 +30,11 @@ export const initializeSnowplow = (url) => { forceSecureTracker: true, contexts: { webPage: true, - performanceTiming: true - } + performanceTiming: true, + }, }); window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds window.snowplow('enableLinkClickTracking'); window.snowplow('trackPageView'); // -} \ No newline at end of file +}; From 85034e5af34e494899e5ec3bb14f3dfd3dca7b74 Mon Sep 17 00:00:00 2001 From: Sukanya Rath Date: Wed, 1 May 2024 16:40:29 -0700 Subject: [PATCH 9/9] fix CaddyFile Signed-off-by: Sukanya Rath --- .github/workflows/ci_cd_on_pr_dev_sandbox.yml | 2 - frontend/Dockerfile | 2 - frontend/index.html | 2 + frontend/public/snowplow.js | 20 ++++++++++ frontend/src/main.js | 3 -- frontend/src/snowplow.js | 40 ------------------- 6 files changed, 22 insertions(+), 47 deletions(-) create mode 100644 frontend/public/snowplow.js delete mode 100644 frontend/src/snowplow.js diff --git a/.github/workflows/ci_cd_on_pr_dev_sandbox.yml b/.github/workflows/ci_cd_on_pr_dev_sandbox.yml index 0c6908a91..60a4e928f 100644 --- a/.github/workflows/ci_cd_on_pr_dev_sandbox.yml +++ b/.github/workflows/ci_cd_on_pr_dev_sandbox.yml @@ -40,8 +40,6 @@ jobs: triggers: ('frontend/') build_file: ./frontend/Dockerfile build_context: ./frontend - build_args: | - VITE_SNOWPLOW_URL=${{ secrets.VITE_SNOWPLOW_URL }} - package: database-migrations triggers: ('backend/db') build_file: ./backend/db/Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c6ff08f3f..c0de6a9b3 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,9 +1,7 @@ # Build static files FROM node:lts-alpine AS build -ARG VITE_SNOWPLOW_URL WORKDIR /app COPY . . -ENV VITE_SNOWPLOW_URL=$VITE_SNOWPLOW_URL RUN npm ci --ignore-scripts && \ npm run build diff --git a/frontend/index.html b/frontend/index.html index 05b1a4236..552091ad3 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,6 +10,7 @@ + FIN Pay Transparency @@ -18,6 +19,7 @@ Please enable JavaScript to continue.
+ diff --git a/frontend/public/snowplow.js b/frontend/public/snowplow.js new file mode 100644 index 000000000..6c8bf92e3 --- /dev/null +++ b/frontend/public/snowplow.js @@ -0,0 +1,20 @@ +// +;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; + p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) + };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; + n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js","snowplow")); +window.snowplow('newTracker','rt',window.config.SNOWPLOW_URL, { + appId: 'Snowplow_standalone', + cookieLifetime: 86400 * 548, + platform: 'web', + post: true, + forceSecureTracker: true, + contexts: { + webPage: true, + performanceTiming: true + } +}); +window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds +window.snowplow('enableLinkClickTracking'); +window.snowplow('trackPageView'); +// diff --git a/frontend/src/main.js b/frontend/src/main.js index 70f7feb46..697e9c37a 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -18,9 +18,6 @@ import 'viewerjs/dist/viewer.css'; import component from 'v-viewer'; import VueDOMPurifyHTML from 'vue-dompurify-html'; -import { initializeSnowplow } from './snowplow'; -/* istanbul ignore next */ -initializeSnowplow(import.meta.env.VITE_SNOWPLOW_URL); const myCustomLightTheme = { dark: false, diff --git a/frontend/src/snowplow.js b/frontend/src/snowplow.js deleted file mode 100644 index d06005cf0..000000000 --- a/frontend/src/snowplow.js +++ /dev/null @@ -1,40 +0,0 @@ -// -/* istanbul ignore next */ -export const initializeSnowplow = (url) => { - (function (p, l, o, w, i, n, g) { - if (!p[i]) { - p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || []; - p.GlobalSnowplowNamespace.push(i); - p[i] = function () { - (p[i].q = p[i].q || []).push(arguments); - }; - p[i].q = p[i].q || []; - n = l.createElement(o); - g = l.getElementsByTagName(o)[0]; - n.async = 1; - n.src = w; - g.parentNode.insertBefore(n, g); - } - })( - window, - document, - 'script', - 'https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js', - 'snowplow', - ); - window.snowplow('newTracker', 'rt', url, { - appId: 'Snowplow_standalone', - cookieLifetime: 86400 * 548, - platform: 'web', - post: true, - forceSecureTracker: true, - contexts: { - webPage: true, - performanceTiming: true, - }, - }); - window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds - window.snowplow('enableLinkClickTracking'); - window.snowplow('trackPageView'); - // -};