|
15 | 15 |
|
16 | 16 | {{ $insights := resources.Get "js/clean-insights.js" }}
|
17 | 17 | {{ $cleaninsights := slice $insights | resources.Concat "clean-insights.js" | resources.Minify }}
|
18 |
| -<script src="{{ $cleaninsights.RelPermalink }}"></script> |
| 18 | +<script src="{{ $cleaninsights.RelPermalink }}" defer></script> |
19 | 19 |
|
20 |
| -<div id="tracking-banner" class="pointer-events-none fixed inset-x-0 bottom-0 px-6 pb-6"> |
| 20 | +<script> |
| 21 | + document.addEventListener('DOMContentLoaded', () => { |
| 22 | + const storedConsent = localStorage.getItem('trackingConsent'); |
| 23 | + if (storedConsent === 'granted') { |
| 24 | + // Automatically grant consent if already stored |
| 25 | + const ci = CleanInsightsAutoTracker("https://metrics.cleaninsights.org/cleaninsights.php", 34); |
| 26 | + ci.grantCampaign('visits'); |
| 27 | + ci.grantFeature(CleanInsightsFeature.ua); |
| 28 | + ci.grantFeature(CleanInsightsFeature.lang); |
| 29 | + return; // Exit if consent is already granted |
| 30 | + } else if (storedConsent === 'denied') { |
| 31 | + // If consent is denied, hide the banner and do not initialize CleanInsights |
| 32 | + document.getElementById('tracking-banner').style.display = 'none'; |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + // Show banner if consent is not given |
| 37 | + document.getElementById('tracking-banner').style.display = 'flex'; |
| 38 | + }); |
| 39 | +</script> |
| 40 | + |
| 41 | +<div id="tracking-banner" class="hidden pointer-events-none fixed inset-x-0 bottom-0 px-6 pb-6"> |
21 | 42 | <div class="pointer-events-auto mx-auto max-w-xl rounded-xl bg-white p-6 shadow-lg ring-1 ring-gray-900/10">
|
22 |
| - <p class="text-sm leading-6 text-gray-900">This website uses <a href="https://cleaninsights.org/">Clean Insights</a> for privacy-preserving web analytics. By using the site you agree to allow the collection of basic country, language, navigation, and user-agent information.</p> |
| 43 | + <p class="text-sm leading-6 text-gray-900 prose">{{ i18n "key.cookie-banner" | markdownify }}</p> |
23 | 44 | <div class="mt-4 flex items-center gap-x-5">
|
24 | 45 | <button id="accept-consent" class="rounded-md bg-gray-900 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-900">
|
25 |
| - Accept |
| 46 | + {{ i18n "key.accept" }} |
26 | 47 | </button>
|
| 48 | + <button id="reject-consent" class="text-sm font-semibold leading-6 text-gray-900">{{ i18n "key.reject" }}</button> |
27 | 49 | </div>
|
28 | 50 | </div>
|
29 | 51 | </div>
|
30 | 52 |
|
31 | 53 | <script>
|
32 | 54 | document.addEventListener('DOMContentLoaded', () => {
|
33 |
| - const ci = CleanInsightsAutoTracker("https://metrics.cleaninsights.org/cleaninsights.php", 34); |
34 |
| - console.log(ci); |
| 55 | + const ci = CleanInsightsAutoTracker("https://metrics.cleaninsights.org/cleaninsights.php", 34); |
| 56 | + |
| 57 | + const banner = document.getElementById('tracking-banner'); |
| 58 | + const acceptButton = document.getElementById('accept-consent'); |
| 59 | + const rejectButton = document.getElementById('reject-consent'); |
| 60 | + |
| 61 | + // Function to handle consent |
| 62 | + const handleConsent = () => { |
| 63 | + banner.style.display = 'none'; |
35 | 64 |
|
36 |
| - const banner = document.getElementById('tracking-banner'); |
37 |
| - const acceptButton = document.getElementById('accept-consent'); |
| 65 | + ci.grantCampaign('visits'); |
| 66 | + ci.grantFeature(CleanInsightsFeature.ua); |
| 67 | + ci.grantFeature(CleanInsightsFeature.lang); |
38 | 68 |
|
39 |
| - // Function to handle consent |
40 |
| - const handleConsent = () => { |
41 |
| - banner.style.display = 'none'; |
| 69 | + // Store consent in localStorage |
| 70 | + localStorage.setItem('trackingConsent', 'granted'); |
| 71 | + }; |
42 | 72 |
|
43 |
| - ci.grantCampaign('visits'); |
44 |
| - ci.grantFeature(CleanInsightsFeature.ua); |
45 |
| - ci.grantFeature(CleanInsightsFeature.lang); |
46 |
| - }; |
| 73 | + // Function to handle rejection |
| 74 | + const handleRejection = () => { |
| 75 | + banner.style.display = 'none'; |
47 | 76 |
|
48 |
| - // Set up button click event |
49 |
| - acceptButton.addEventListener('click', handleConsent); |
| 77 | + // Store rejection in localStorage |
| 78 | + localStorage.setItem('trackingConsent', 'denied'); |
| 79 | + }; |
50 | 80 |
|
51 |
| - // Show banner if consent is not given |
52 |
| - if (!ci.campaignConsents.some(item => item === 'visits')) { |
53 |
| - banner.style.display = 'flex'; |
54 |
| - } |
| 81 | + // Set up button click events |
| 82 | + acceptButton.addEventListener('click', handleConsent); |
| 83 | + rejectButton.addEventListener('click', handleRejection); |
55 | 84 | });
|
56 | 85 | </script>
|
57 | 86 |
|
|
0 commit comments