-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie-consent-config.js
executable file
·77 lines (67 loc) · 1.77 KB
/
cookie-consent-config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { message, privacyPolicyLink, cookiePolicyLink, name, domain, gaId, gtmId } = cookieConsentSettings;
const CookieConsent = window.CookieConsent;
const cc = new CookieConsent({
position: "bottom",
type: "opt-in",
consentSettingsElementId: "btn-revokeChoice",
layout: "categories",
showCategories: {
[CookieConsent.UNCATEGORIZED]: false,
[CookieConsent.ESSENTIAL]: true,
[CookieConsent.PERSONALIZATION]: false,
[CookieConsent.ANALYTICS]: true,
[CookieConsent.MARKETING]: false,
},
content: {
message,
privacyPolicyLink,
cookiePolicyLink,
},
cookie: {
domain,
name,
},
});
cc.on("initialized", function () {
const { consents } = cc;
if (consents[CookieConsent.ESSENTIAL] !== CookieConsent.ALLOW) {
cc.open();
}
if (consents[CookieConsent.ANALYTICS] === CookieConsent.ALLOW) {
initializeGTM();
}
});
cc.on("popupClosed", function () {
const { consents } = cc;
if (consents[CookieConsent.ANALYTICS] === CookieConsent.ALLOW) {
initializeGTM();
} else {
removeAnalyticsCookies();
if (isGTMInitialized()) {
location.reload();
}
}
});
function isGTMInitialized() {
return window.gtmInitialized;
}
function initializeGTM() {
if (!isGTMInitialized()) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
"gtm.start": new Date().getTime(),
event: "gtm.js",
});
var f = document.getElementsByTagName("script")[0];
var j = document.createElement("script");
j.async = true;
j.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`;
f.parentNode.insertBefore(j, f);
window.gtmInitialized = true;
}
}
function removeAnalyticsCookies() {
cc.deleteCookie("_ga");
cc.deleteCookie("_gid");
cc.deleteCookie(`_gat_${gaId}`);
}