hof 20.3.7-beta-gtm → 20.3.9-beta-gtm

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,18 @@ 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, serviceName) {
30
+ switch (serviceName) {
31
+ // Add other services here...
32
+ default:
33
+ return convertPage(page);
34
+ }
35
+ }
36
+ },
26
37
  gaCrossDomainTrackingTagId: process.env.GDS_CROSS_DOMAIN_GA_TAG,
27
38
  loglevel: process.env.LOG_LEVEL || 'info',
28
39
  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,17 +73,13 @@ 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
- pageEvent: '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
  });
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.7-beta-gtm",
4
+ "version": "20.3.9-beta-gtm",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",