hof 20.2.20 → 20.2.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,11 +62,11 @@
62
62
 
63
63
  {{#gtmTagId}}
64
64
  <!-- Data Layer -->
65
- <script {{#nonce}} nonce="{{nonce}}"{{/nonce}}>
66
- dataLayer.push({window.dataLayer = window.dataLayer || [];
67
- window.dataLayer.push({
65
+ <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
66
+ window.dataLayer = window.dataLayer || [];
67
+ dataLayer.push({
68
68
  'event': 'pageLoad',
69
- 'pageName': 'ETA | Customer Contact Webform | {{ga-page}}'
69
+ 'pageName': 'ETA | Customer Contact Webform | {{gtm-page}}',
70
70
  'applicationType': 'ETA | Customer Contact',
71
71
  'environmentType': {{^gaAllowDebug}}'dev'{{/gaAllowDebug}}{{#gaAllowDebug}}'prod'{{/gaAllowDebug}}
72
72
  });
@@ -74,7 +74,7 @@
74
74
  <!-- End Data Layer -->
75
75
 
76
76
  <!-- Google Tag Manager for ETA -->
77
- <script {{#nonce}} nonce="{{nonce}}"{{/nonce}}>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
77
+ <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
78
78
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
79
79
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
80
80
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
package/lib/ga-tag.js CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
+ const convertToGTMPage = (text) => {
6
+ // Remove leading and trailing slashes
7
+ let str = text.replace(/^\/|\/$/g, '');
8
+ // Replace hyphens with spaces and capitalize each word
9
+ str = str.replace(/-+/g, ' ').replace(/(^|\s)\S/g, function(match) {
10
+ return match.toUpperCase();
11
+ });
12
+ return str;
13
+ }
14
+
5
15
  const pageView = (path, pageMap) => pageMap.get(path) || path;
6
16
 
7
17
  const createUris = routes => {
@@ -51,6 +61,7 @@ const setupPageMap = routes => {
51
61
  const pageMap = setupPageMap(routes);
52
62
 
53
63
  app.use((req, res, next) => {
64
+ const page = pageView(req.path, pageMap);
54
65
  res.locals.gaAllowDebug = config.env === 'development';
55
66
  res.locals.gaTagId = gaTagId;
56
67
  res.locals.ga4TagId = ga4TagId;
@@ -58,7 +69,8 @@ const setupPageMap = routes => {
58
69
  res.locals.appName = appName
59
70
  res.locals.gaCrossDomainTrackingTagId = gaCrossDomainTrackingTagId;
60
71
  res.locals['ga-id'] = gaTagId;
61
- res.locals['ga-page'] = pageView(req.path, pageMap);
72
+ res.locals['ga-page'] = page
73
+ res.locals['gtm-page'] = convertToGTMPage(page)
62
74
  next();
63
75
  });
64
76
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hof",
3
3
  "description": "A bootstrap for HOF projects",
4
- "version": "20.2.20",
4
+ "version": "20.2.22",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",