Skip to content

Commit c0ba412

Browse files
committed
Fixed consent banner
1 parent ca84797 commit c0ba412

File tree

6 files changed

+99
-22
lines changed

6 files changed

+99
-22
lines changed

assets/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

i18n/ar.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@ key:
424424
translation:
425425
one: null
426426
other: "تعديل هذه الصفحة على GitHub"
427+
- id: cookie-banner
428+
translation:
429+
one: null
430+
other: يستخدم هذا الموقع [Clean Insights](https://cleaninsights.org/) لتحليلات الويب التي تحافظ على الخصوصية. باستخدامك للموقع، فإنك توافق على السماح بجمع المعلومات الأساسية مثل البلد، واللغة، والتنقل، ووكيل المستخدم.
431+
- id: accept
432+
translation:
433+
one: null
434+
other: قبول
435+
- id: reject
436+
translation:
437+
one: null
438+
other: رفض
427439
- id: January
428440
translation:
429441
one: null

i18n/en.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,18 @@ key:
445445
translation:
446446
one: null
447447
other: Edit this page on GitHub
448+
- id: cookie-banner
449+
translation:
450+
one: null
451+
other: This website uses [Clean Insights](https://cleaninsights.org/) for privacy-preserving web analytics. By using the site you agree to allow the collection of basic country, language, navigation, and user-agent information.
452+
- id: accept
453+
translation:
454+
one: null
455+
other: Accept
456+
- id: reject
457+
translation:
458+
one: null
459+
other: Reject
448460
- id: January
449461
translation:
450462
one: null

i18n/es.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ key:
418418
other: "La información de Git no está disponible."
419419
- id: edit-github
420420
other: "Editar esta página en GitHub"
421+
- id: cookie-banner
422+
translation:
423+
one: null
424+
other: Este sitio web utiliza [Clean Insights](https://cleaninsights.org/) para realizar análisis web que respetan la privacidad. Al usar el sitio, aceptas permitir la recopilación de información básica sobre el país, el idioma, la navegación y el agente de usuario.
425+
- id: accept
426+
translation:
427+
one: null
428+
other: Aceptar
429+
- id: reject
430+
translation:
431+
one: null
432+
other: Rechazar
421433
- id: January
422434
translation:
423435
one: null

i18n/fr.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ key:
327327
- id: edit-github
328328
one: null
329329
other: "Modifier cette page sur GitHub"
330+
- id: cookie-banner
331+
translation:
332+
one: null
333+
other: Ce site utilise [Clean Insights](https://cleaninsights.org/) pour des analyses web respectueuses de la vie privée. En utilisant ce site, vous acceptez la collecte d'informations de base telles que le pays, la langue, la navigation et l'agent utilisateur.
334+
- id: accept
335+
translation:
336+
one: null
337+
other: Accepter
338+
- id: reject
339+
translation:
340+
one: null
341+
other: Rejeter
330342
- id: January
331343
one: null
332344
other: "Janvier"

layouts/partials/javascript.html

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,72 @@
1515

1616
{{ $insights := resources.Get "js/clean-insights.js" }}
1717
{{ $cleaninsights := slice $insights | resources.Concat "clean-insights.js" | resources.Minify }}
18-
<script src="{{ $cleaninsights.RelPermalink }}"></script>
18+
<script src="{{ $cleaninsights.RelPermalink }}" defer></script>
1919

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">
2142
<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>
2344
<div class="mt-4 flex items-center gap-x-5">
2445
<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" }}
2647
</button>
48+
<button id="reject-consent" class="text-sm font-semibold leading-6 text-gray-900">{{ i18n "key.reject" }}</button>
2749
</div>
2850
</div>
2951
</div>
3052

3153
<script>
3254
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';
3564

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);
3868

39-
// Function to handle consent
40-
const handleConsent = () => {
41-
banner.style.display = 'none';
69+
// Store consent in localStorage
70+
localStorage.setItem('trackingConsent', 'granted');
71+
};
4272

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';
4776

48-
// Set up button click event
49-
acceptButton.addEventListener('click', handleConsent);
77+
// Store rejection in localStorage
78+
localStorage.setItem('trackingConsent', 'denied');
79+
};
5080

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);
5584
});
5685
</script>
5786

0 commit comments

Comments
 (0)