hof 20.3.5-beta-gtm → 20.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,14 @@ const defaults = {
22
22
  env: process.env.NODE_ENV || 'development',
23
23
  gaTagId: process.env.GA_TAG || 'Test-GA-Tag',
24
24
  ga4TagId: process.env.GA_4_TAG,
25
- gtmTagId: process.env.GTM_TAG || false,
25
+ // added to allow support for multiple HOF forms using GTM to customize how they track page views
26
+ gtm: {
27
+ tagId: process.env.GTM_TAG || false,
28
+ config: {},
29
+ composePageName: function (page, convertPage) {
30
+ return convertPage(page);
31
+ }
32
+ },
26
33
  gaCrossDomainTrackingTagId: process.env.GDS_CROSS_DOMAIN_GA_TAG,
27
34
  loglevel: process.env.LOG_LEVEL || 'info',
28
35
  ignoreMiddlewareLogs: ['/healthz'],
@@ -1,18 +1,13 @@
1
1
  {{#gtmTagId}}
2
2
  {{#cookiesAccepted}}
3
- {{#isETA}}
4
- <!-- Google Tag Manager Data Layer for ETA -->
3
+ <!-- Google Tag Manager Data Layer -->
5
4
  <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
6
5
  var dataLayer = window.dataLayer || [];
7
- dataLayer.push({
8
- 'event': 'pageLoad',
9
- 'pageName': 'ETA | Customer Contact Webform | {{gtm-page}}',
10
- 'applicationType': 'ETA | Customer Contact',
11
- 'environmentType': '{{environmentType}}'
12
- });
6
+ dataLayer.push(
7
+ {{{gtmConfig}}}
8
+ );
13
9
  </script>
14
- <!-- End Google Tag Manager Data Layer for ETA -->
15
- {{/isETA}}
10
+ <!-- End Google Tag Manager Data Layer -->
16
11
 
17
12
  <!-- Google Tag Manager -->
18
13
  <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
package/lib/ga-tag.js CHANGED
@@ -52,26 +52,35 @@ const setupPageMap = routes => {
52
52
  module.exports = (app, config) => {
53
53
  const gaTagId = config.gaTagId;
54
54
  const ga4TagId = config.ga4TagId;
55
- const gtmTagId = config.gtmTagId;
56
- const environmentType = config.environmentType ? config.environmentType : 'dev';
55
+ const gtm = config.gtm;
57
56
  const gaCrossDomainTrackingTagId = config.gaCrossDomainTrackingTagId;
58
57
  const routes = config.routes;
59
58
 
60
- if (gaTagId || ga4TagId) {
59
+ if (gaTagId || ga4TagId || gtm.tagId) {
61
60
  const pageMap = setupPageMap(routes);
62
61
 
63
62
  app.use((req, res, next) => {
64
63
  const page = pageView(req.path, pageMap);
65
- res.locals.gaAllowDebug = config.env === 'development';
66
- res.locals.isETA = config.appName.includes('ETA');
67
- res.locals.gaTagId = gaTagId;
68
- res.locals.ga4TagId = ga4TagId;
69
- res.locals.gtmTagId = gtmTagId;
70
- res.locals.environmentType = environmentType;
71
- res.locals.gaCrossDomainTrackingTagId = gaCrossDomainTrackingTagId;
72
- res.locals['ga-id'] = gaTagId;
73
- res.locals['ga-page'] = page;
74
- res.locals['gtm-page'] = convertToGTMPage(page);
64
+
65
+ // Preparing common res.locals properties
66
+ const properties = {
67
+ gaAllowDebug: config.env === 'development',
68
+ gaTagId: gaTagId,
69
+ ga4TagId: ga4TagId,
70
+ gaCrossDomainTrackingTagId: gaCrossDomainTrackingTagId,
71
+ 'ga-id': gaTagId,
72
+ 'ga-page': page
73
+ };
74
+
75
+ // Adding extra properties if a GTM TAG is available
76
+ if (gtm.tagId) {
77
+ gtm.config.pageName = gtm.composePageName(page, convertToGTMPage);
78
+ Object.assign(properties, {
79
+ gtmConfig: JSON.stringify(gtm.config),
80
+ gtmTagId: gtm.tagId
81
+ });
82
+ }
83
+ res.locals = Object.assign(res.locals, properties);
75
84
  next();
76
85
  });
77
86
  }
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.3.5-beta-gtm",
4
+ "version": "20.3.5",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",