-
Notifications
You must be signed in to change notification settings - Fork 92
/
gatsby-ssr.js
48 lines (47 loc) · 1.46 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const React = require('react')
exports.onRenderBody = function ({ setPreBodyComponents }) {
setPreBodyComponents([
React.createElement('script', {
src: 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js',
'data-domain-script': '018ee325-b3a7-7753-937b-b8b3e643b1a7',
}),
React.createElement('script', {
dangerouslySetInnerHTML: {
__html: `function OptanonWrapper() {}`,
},
}),
React.createElement('script', {
dangerouslySetInnerHTML: {
__html: `
function setGTM(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
}
if (document.cookie.indexOf('OptanonConsent') > -1 && document.cookie.indexOf('groups=') > -1) {
setGTM(window, document, 'script', 'dataLayer', 'GTM-W8CQ8TL');
} else {
waitForOnetrustActiveGroups();
}
var timer;
function waitForOnetrustActiveGroups() {
if (document.cookie.indexOf('OptanonConsent') > -1 && document.cookie.indexOf('groups=') > -1) {
clearTimeout(timer);
setGTM(window, document, 'script', 'dataLayer', 'GTM-W8CQ8TL');
} else {
timer = setTimeout(waitForOnetrustActiveGroups, 250);
}
}
`,
},
}),
])
}