diff --git a/assets/js/cookieconsent.js b/assets/js/cookieconsent.js
index deed6c5..326593c 100644
--- a/assets/js/cookieconsent.js
+++ b/assets/js/cookieconsent.js
@@ -3,39 +3,29 @@
'use strict';
- if (typeof Cookies !== 'undefined') {
- const cookieconsent = document.querySelector('.cookieconsent');
+ const cookiebanner = document.querySelector('.cookieconsent');
+ const cookieconsent = localStorage.getItem('cookieconsent');
- if (typeof Cookies.get('cookieconsent') === 'undefined' && cookieconsent) {
- cookieconsent.classList.remove('hidden');
- cookieconsent.classList.add('js-cookieconsent-open');
- }
-
- const cookie_buttons = Array.prototype.slice.call(
- document.querySelectorAll('button[data-consent]')
- );
- const sitedomain = window.location.hostname.split('.').slice(-2);
- const cookiedomain = sitedomain.join('.');
- let cookie_options = [];
- cookie_options['domain'] = cookiedomain;
- cookie_options['sameSite'] = 'strict';
- cookie_options['expires'] = 365;
- if (window.location.protocol === 'https:') {
- cookie_options['secure'] = true;
- }
-
- cookie_buttons.forEach(function (button) {
- button.addEventListener('click', function () {
- if (button.getAttribute('data-consent') === 'true') {
- Cookies.set('cookieconsent', 'accept', cookie_options);
- }
- else {
- Cookies.set('cookieconsent', 'decline', cookie_options);
- }
- cookieconsent.classList.remove('js-cookieconsent-open');
- cookieconsent.classList.add('hidden');
- });
- });
+ if (cookiebanner && !cookieconsent) {
+ cookiebanner.classList.remove('hidden');
+ cookiebanner.classList.add('js-cookieconsent-open');
}
+ const cookie_buttons = Array.prototype.slice.call(
+ document.querySelectorAll('button[data-consent]')
+ );
+
+ cookie_buttons.forEach(function (button) {
+ button.addEventListener('click', function () {
+ if (button.getAttribute('data-consent') === 'true') {
+ localStorage.setItem('cookieconsent', 'accept');
+ }
+ else {
+ localStorage.setItem('cookieconsent', 'decline');
+ }
+ cookiebanner.classList.remove('js-cookieconsent-open');
+ cookiebanner.classList.add('hidden');
+ });
+ });
+
})();
diff --git a/assets/js/tracking.js b/assets/js/tracking.js
index 75f6807..e28209c 100644
--- a/assets/js/tracking.js
+++ b/assets/js/tracking.js
@@ -5,26 +5,26 @@
* A JavaScript file for analytic tracking.
*/
-var cookieConsent = {{ .Site.Params.cookieConsent | default false }};
-
+var cookiebanner = {{ .Site.Params.cookieConsent | default false }};
+var cookieconsent = localStorage.getItem('cookieconsent');
var idSite = '{{ .Site.Params.piwikSiteID }}';
var matomoTrackingApiUrl = 'https://{{ .Site.Params.piwikTrackerUrl }}/matomo.php';
-
-var _paq = window._paq || [];
-if (cookieConsent) {
- _paq.push(['requireConsent']);
-}
-_paq.push(['setTrackerUrl', matomoTrackingApiUrl]);
-_paq.push(['setSiteId', idSite]);
-_paq.push(['trackPageView']);
-_paq.push(['enableLinkTracking']);
-if (typeof Cookies !== 'undefined' && Cookies.get('cookieconsent') === 'accept') {
- _paq.push(['setConsentGiven']);
-}
-
var googleAnalytics = '{{ .Site.GoogleAnalytics }}';
-if (cookieConsent) {
- if (typeof Cookies === 'undefined' || Cookies.get('cookieconsent') !== 'accept') {
- window['ga-disable-' + googleAnalytics] = true;
+
+if (idSite) {
+ var _paq = window._paq || [];
+ if (cookiebanner) {
+ _paq.push(['requireConsent']);
+ }
+ _paq.push(['setTrackerUrl', matomoTrackingApiUrl]);
+ _paq.push(['setSiteId', idSite]);
+ _paq.push(['trackPageView']);
+ _paq.push(['enableLinkTracking']);
+ if (cookiebanner && cookieconsent === 'accept') {
+ _paq.push(['setConsentGiven']);
}
}
+
+if (googleAnalytics && cookiebanner && cookieconsent === 'decline') {
+ window['ga-disable-' + googleAnalytics] = true;
+}
diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html
index 50834e0..c578138 100644
--- a/layouts/partials/scripts.html
+++ b/layouts/partials/scripts.html
@@ -11,8 +11,6 @@
{{ end -}}
{{ if $.Param "cookieconsent" -}}
-{{ $jscookie := resources.Get "js/lib/js.cookie.min.js" | fingerprint -}}
-
{{ $cookieconsent := resources.Get "js/cookieconsent.js" | minify | fingerprint -}}
{{ end -}}