hof 20.3.4 → 20.3.5
Sign up to get free protection for your applications and to get access to all the features.
package/config/hof-defaults.js
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
9
|
-
|
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
|
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
|
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
|
-
|
66
|
-
res.locals
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
}
|