-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics-wrapper.js
More file actions
54 lines (51 loc) · 1.99 KB
/
analytics-wrapper.js
File metadata and controls
54 lines (51 loc) · 1.99 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
// Analytics Wrapper - Loads analytics only after consent
(function() {
// Function to load Vercel Analytics
function loadVercelAnalytics() {
if (!document.querySelector('script[src*="vercel-insights"]')) {
var script = document.createElement('script');
script.defer = true;
script.src = 'https://cdn.vercel-insights.com/v1.js';
document.head.appendChild(script);
}
}
// Function to load RB2B tracking
function loadRB2B() {
if (!window.reb2b) {
!function(key) {
if (window.reb2b) return;
window.reb2b = {loaded: true};
var s = document.createElement("script");
s.async = true;
s.src = "https://b2bjsstore.s3.us-west-2.amazonaws.com/b/" + key + "/" + key + ".js.gz";
document.getElementsByTagName("script")[0].parentNode.insertBefore(s, document.getElementsByTagName("script")[0]);
}("VN080HX77V6J");
}
}
// Check consent and load scripts
document.addEventListener('DOMContentLoaded', function() {
// Check if CookieConsent is available
if (window.CookieConsent) {
// Listen for consent changes
window.CookieConsent.on('consent:accepted', function(cookie) {
if (cookie.categories.includes('analytics')) {
loadVercelAnalytics();
loadRB2B();
}
});
// Check initial consent state
if (window.CookieConsent.acceptedCategory('analytics')) {
loadVercelAnalytics();
loadRB2B();
}
} else {
// If CookieConsent not loaded, wait for it
window.addEventListener('cc:onConsent', function() {
if (window.CookieConsent.acceptedCategory('analytics')) {
loadVercelAnalytics();
loadRB2B();
}
});
}
});
})();