-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathanalytics.html.bak
More file actions
51 lines (45 loc) · 1.81 KB
/
analytics.html.bak
File metadata and controls
51 lines (45 loc) · 1.81 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
<!-- Determine analytics provider -->
{% if config.extra.analytics %}
{% set provider = config.extra.analytics.provider %}
{% endif %}
<!-- Set up analytics provider -->
{% if provider %}
{% include "partials/integrations/analytics/" ~ provider ~ ".html" %}
{% if config.extra.consent %}
<script>
// Initialize Matomo's _paq array
window._paq = window._paq || [];
window._paq.push(['requireCookieConsent']);
// Check initial consent and load analytics
var consent = __md_get("__consent");
if (consent && consent.analytics) {
console.log(`We have analytics liftoff. Value of consent, ${consent.analytics}`);
window._paq.push(['rememberCookieConsentGiven']); // Remember consent
__md_analytics(); // Load Matomo if consent is given
}
else if (!consent) { // Load consent popup
console.log('It looks like you have not explicitly consented to analytics. Let us fix that.')
window.location.href = "#__consent";
}
else if (consent && !consent.analytics) {
console.log(`The launch of our analytics rocket is postponed. Value of consent, ${consent.analytics}`)
}
// Monitor local storage for changes in consent
window.addEventListener("storage", function (event) {
if (event.key === "__consent") {
var updatedConsent = __md_get("__consent");
if (updatedConsent && updatedConsent.analytics) {
// Consent granted
window._paq.push(['rememberCookieConsentGiven']);
__md_analytics();
__md_feedback();
} else {
// Consent revoked or not set
window._paq.push(['forgetCookieConsentGiven']);
console.log(`Analytics consent revoked. Consent value = ${updatedConsent.analytics}. Analytics disabled.`);
}
}
});
</script>
{% endif %}
{% endif %}