-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.js
53 lines (51 loc) · 1.49 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
49
50
51
52
53
const React = require("react");
const { oneLineTrim } = require("common-tags");
export const onRenderBody = (
{ setHeadComponents, setPreBodyComponents },
{
account,
profile,
env,
injectUtagSync = false,
disableInitialTracking = false
}
) => {
if (["dev", "qa", "prod"].includes(env)) {
if (injectUtagSync) {
setHeadComponents([
React.createElement("script", {
key: "plugin-tealium-utag-sync",
src: `https://tags.tiqcdn.com/utag/${account}/${profile}/${env}/utag.sync.js`
})
]);
}
setPreBodyComponents([
React.createElement("script", {
key: "plugin-tealium-utag",
dangerouslySetInnerHTML: {
__html: oneLineTrim`
${
disableInitialTracking
? `
window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.noview = true;
`
: ""
}
(function(a,b,c,d){
a='//tags.tiqcdn.com/utag/${account}/${profile}/${env}/utag.js';
b=document;c='script';d=b.createElement(c);
d.onload=function() { b.dispatchEvent(new Event("utag-loaded")); };
d.src=a;d.type='text/java'+c;d.async=true;
a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a)
})();
`
}
})
]);
} else {
throw new Error(
`Unknown env: [${env}]. env must be "dev", "qa", or "prod".`
);
}
};