hof 20.3.6-beta-gtm → 20.3.6

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'],
@@ -3,12 +3,9 @@
3
3
  <!-- Google Tag Manager Data Layer -->
4
4
  <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
5
5
  var dataLayer = window.dataLayer || [];
6
- dataLayer.push({
7
- 'event': '{{pageEvent}}',
8
- 'pageName': '{{pageName}}',
9
- 'applicationType': '{{applicationType}}',
10
- 'environmentType': '{{environmentType}}'
11
- });
6
+ dataLayer.push(
7
+ {{{gtmConfig}}}
8
+ );
12
9
  </script>
13
10
  <!-- End Google Tag Manager Data Layer -->
14
11
 
package/lib/ga-tag.js CHANGED
@@ -52,12 +52,11 @@ 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 || gtmTagId) {
59
+ if (gaTagId || ga4TagId || gtm.tagId) {
61
60
  const pageMap = setupPageMap(routes);
62
61
 
63
62
  app.use((req, res, next) => {
@@ -74,47 +73,17 @@ module.exports = (app, config) => {
74
73
  };
75
74
 
76
75
  // Adding extra properties if a GTM TAG is available
77
- if (gtmTagId) {
76
+ if (gtm.tagId) {
77
+ gtm.config.pageName = gtm.composePageName(page, convertToGTMPage);
78
78
  Object.assign(properties, {
79
- gtmTagId: gtmTagId,
80
- 'gtm-page': convertToGTMPage(page),
81
- eventName: 'pageLoad',
82
- pageName: `ETA | Customer Contact Webform | ${convertToGTMPage(page)}`,
83
- applicationType: 'ETA | Customer Contact',
84
- environmentType: environmentType
79
+ gtmConfig: JSON.stringify(gtm.config),
80
+ gtmTagId: gtm.tagId
85
81
  });
86
82
  }
87
-
88
83
  res.locals = Object.assign(res.locals, properties);
89
84
  next();
90
85
  });
91
86
  }
92
87
 
93
- /*
94
- if (gaTagId || ga4TagId || gtmTagId) {
95
- const pageMap = setupPageMap(routes);
96
-
97
- app.use((req, res, next) => {
98
- const page = pageView(req.path, pageMap);
99
- res.locals.gaAllowDebug = config.env === 'development';
100
-
101
- if (gtmTagId) {
102
- res.locals.gtmTagId = gtmTagId;
103
- res.locals['gtm-page'] = convertToGTMPage(page);
104
- res.locals.eventName = "pageLoad"
105
- res.locals.pageName = `ETA | Customer Contact Webform | ${res.locals['gtm-page']}`
106
- res.locals.applicationType = "ETA | Customer Contact"
107
- res.locals.environmentType = environmentType;
108
- }
109
- res.locals.gaTagId = gaTagId;
110
- res.locals.ga4TagId = ga4TagId;
111
- res.locals.gaCrossDomainTrackingTagId = gaCrossDomainTrackingTagId;
112
- res.locals['ga-id'] = gaTagId;
113
- res.locals['ga-page'] = page;
114
- next();
115
- });
116
- }
117
- */
118
-
119
88
  return app;
120
89
  };
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.6-beta-gtm",
4
+ "version": "20.3.6",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",