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