-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-consent.html
92 lines (81 loc) · 2.77 KB
/
update-consent.html
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
83
84
85
86
87
88
89
90
91
92
<script data-cfasync="false">
/*
Web Site Advantage: Update Consent [v1.0]
Ability to update the BigCommerce consent status using updateConsent(analytics, functional, advertising)
https://bigcommerce.websiteadvantage.com.au/
Copyright (C) 2022 Web Site Advantage
*/
!function(w,d) {
// BigCommerce's Consent system needs to be on for this to work
// hack to hide their banners
function hideBigCommerceBanners() {
var css = '#consent-manager-update-banner, #consent-manager { display:none; visibility : hidden; }',
head = d.head || d.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
hideBigCommerceBanners();
// BCs mechanism to disable scripts until consent is granted
function checkAndLoadScript(e, n=[]) {
const o = e.dataset.bcCookieConsent;
if (void 0 === o)
return !1;
const t = Number(o);
if (isNaN(t))
return !1;
if (n.includes(t) && "text/plain" === e.type) {
const n = e.cloneNode(!0);
n.type = "text/javascript";
const o = e.parentElement;
e.remove(),
o.appendChild(n)
}
}
function loadAllowedScripts(e) {
d.querySelectorAll("[data-bc-cookie-consent]").forEach(n=>checkAndLoadScript(n, e.allow))
}
w.updateConsent = function(analytics, functional, advertising) {
// 2 = Analytics
// 3 = Functional
// 4 = Targeting; Advertising
var consent = {"allow": [],"deny": []};
if (analytics) {
consent.allow.push(2);
} else {
consent.deny.push(2);
}
if (functional) {
consent.allow.push(3);
} else {
consent.deny.push(3);
}
if (advertising) {
consent.allow.push(4);
} else {
consent.deny.push(4);
}
// https://developer.bigcommerce.com/api-reference/6fc489ff8267a-set-cookie-consent-preferences
fetch("/api/storefront/consent", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(consent)
}).then(function() {
if(window.consentManagerStoreConfig().improvedConsentManagerEnabled) {
loadAllowedScripts(consent)
} else {
document.location.reload(!0)
}
}).catch(function(e) {
console.log('updateConsent failed',e)
})
}
}(window, document)
</script>