diff --git a/src/assets/js/cookieConsent.js b/src/assets/js/cookieConsent.js new file mode 100644 index 0000000..a11ac9a --- /dev/null +++ b/src/assets/js/cookieConsent.js @@ -0,0 +1,40 @@ +const cookieStorage = { + getItem: (key) => { + const cookies = document.cookie + .split(";") + .map((cookie) => cookie.split("=")) + .reduce( + (acc, [key, value]) => ({ ...acc, [key.trim()]: value }), {} + ); + return cookies[key]; + }, + setItem: (key, value) => { + document.cookie = `${key}=${value}`; + }, + }; + + const storageType = cookieStorage; + const consentPropertyName = "Audacity_consent"; + + const showShowPopup = () => !storageType.getItem(consentPropertyName); + const saveToStorage = () => + storageType.setItem(consentPropertyName, true); + + window.onload = () => { + const consentPopup = document.getElementById('consent-popup'); + const acceptBtn = document.getElementById('accept'); + + const acceptFn = event => { + saveToStorage(storageType); + consentPopup.classList.add('hide'); + } + + acceptBtn.addEventListener('click', acceptFn); + + if (showShowPopup(storageType)) { + setTimeout(() => { + consentPopup.classList.remove('hide') + }, 2000); + + } + }; \ No newline at end of file diff --git a/src/components/banner/CookieConsent.jsx b/src/components/banner/CookieConsent.jsx new file mode 100644 index 0000000..10c02f4 --- /dev/null +++ b/src/components/banner/CookieConsent.jsx @@ -0,0 +1,18 @@ +import React from 'react' + +function CookieConsent() { + return ( +
+ We use a privacy preserving first-party analytics service if you consent. Otherwise, only necessary cookies are used. Read cookie policy
+ Accept +