-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinjectScriptPlugin.js
More file actions
82 lines (82 loc) · 3.05 KB
/
Copy pathinjectScriptPlugin.js
File metadata and controls
82 lines (82 loc) · 3.05 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module.exports = function (context, options) {
return {
name: 'inject-script-plugin',
injectHtmlTags() {
return {
headTags: [
{
tagName: 'script',
innerHTML: `
function loadGTM() {
if (window.gtmLoaded) return;
window.gtmLoaded = true;
(function(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];
var j=d.createElement(s);
var dl=l!=='dataLayer' ? '&l='+l : '';
j.async=true;
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
f.parentNode.insertBefore(j,f);
})(window, document, 'script', 'dataLayer', 'GTM-P83WH82S');
}
function scheduleGTM() {
if (document.readyState === 'complete') {
window.setTimeout(loadGTM, 3500);
return;
}
window.addEventListener('load', function onLoad() {
window.removeEventListener('load', onLoad);
window.setTimeout(loadGTM, 3500);
}, { once: true });
}
if (typeof requestIdleCallback !== 'undefined') {
requestIdleCallback(scheduleGTM, { timeout: 4000 });
} else {
scheduleGTM();
}
`,
},
{
tagName: 'script',
innerHTML: `
function loadAnalytics() {
if (window.analyticsLoaded) return;
window.analyticsLoaded = true;
var s = document.createElement('script');
s.defer = true;
s.src = 'https://stats.tier.bot/script.js';
s.setAttribute('data-website-id', '09a60445-7371-492c-9d75-c17be79fa569');
s.setAttribute('data-domains', 'hol.org');
document.head.appendChild(s);
}
function scheduleAnalytics() {
if (document.readyState === 'complete') {
window.setTimeout(loadAnalytics, 2500);
return;
}
window.addEventListener('load', function onLoad() {
window.removeEventListener('load', onLoad);
window.setTimeout(loadAnalytics, 2500);
}, { once: true });
}
if (typeof requestIdleCallback !== 'undefined') {
requestIdleCallback(scheduleAnalytics, { timeout: 3500 });
} else {
scheduleAnalytics();
}
`,
},
],
preBodyTags: [
{
tagName: 'noscript',
innerHTML:
'<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P83WH82S" height="0" width="0" style="display:none;visibility:hidden"></iframe>',
},
],
};
},
};
};