Skip to content

Commit

Permalink
SIR-669: Feature/sir 669 (#79)
Browse files Browse the repository at this point in the history
* enable google analytics for the service

* bumping to 0.2.0 for build testing

* moving webpack to prod dependencies as container needs it

* adding in echo for ado build

* trying to inject GA_ID into dockerfile build

* setting GA cookie domains

* sonarcloud stuff

* taking out the GA_ID pipeline echos

* updating variable to camel

* tring to get client coverage not covered by sonar

* removing config.js files from coverage report

* excluding config.js files from sonar
  • Loading branch information
teddmason authored Mar 18, 2024
1 parent 6411661 commit 68bb7e7
Show file tree
Hide file tree
Showing 11 changed files with 1,366 additions and 99 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ It's defined as a build task and can be run using `npm run lint`.

# Environment variables

Environment variables and their default values if not set can be found in the file `server/utils/config.js`
Environment variables for the webapp and their default values if not set can be found in the file `server/utils/config.js`

The build of the webapp requires an environment variable GA_ID if google analytics is required

# Private beta authentication

Expand Down
2 changes: 2 additions & 0 deletions bin/build-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
webpack
1 change: 1 addition & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
rm -rf server/public
npm run build:js
npm run copy:static
npm run build:css
23 changes: 23 additions & 0 deletions client/js/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
// "sir" represents the global namespace for client side js across the service
window.sir = {
utils: {
setupGoogleTagManager: () => {
const gaId = process.env.GA_ID
if (gaId) {
const script = document.createElement('script')
script.src = `https://www.googletagmanager.com/gtag/js?id=${gaId}`
script.onload = () => {
window.dataLayer = window.dataLayer || []
function gtag () { window.dataLayer.push(arguments) }
gtag('js', new Date())
gtag('config', gaId, { cookie_domain: window.location.hostname })
}
document.body.appendChild(script)
}
}
}
}

// Just initialise GA for all page views atm, cookie banner and opt in is to come
window.sir.utils.setupGoogleTagManager()
2 changes: 2 additions & 0 deletions docker/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
context: ../
dockerfile: dockerfile
args:
- GA_ID
ports:
- "8000:8000"
environment:
Expand Down
1 change: 1 addition & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM node:18-alpine

LABEL author="DEFRA"
ARG GA_ID
ENV NODE_ENV=production
ENV PORT=8000

Expand Down
Loading

0 comments on commit 68bb7e7

Please sign in to comment.