By default the cookie that remembers a user's consent (CookieConsent) has a lifespan of 12 months. There are a number of ways to change this:
Renew consent after 6 months
If you would like to reduce the cookie's lifespan, you can do so by adding this script to the page:
<script type="text/javascript">
window.addEventListener("CookiebotOnLoad", function() {
var consentDate = new Date(CookieConsent.consentUTC),
checkDate = new Date(),
now = new Date();
checkDate.setMonth(consentDate.getMonth()+6);
checkDate <= now && (CookieConsent.deleteConsentCookie(), CookieConsent.show());
});
</script>
This remove the consent cookie once it is more than 6 months old and asks the visitor to renew consent.
Renew consent on every session
If you want the banner to ask for consent on every visit, you can also make the CookieConsent cookie session based. This means that the consent settings will be forgotten when you close the browser. This is useful if you have a device used by several users:
<script type="text/javascript">
window.addEventListener("CookiebotOnLoad", function () {
var cookies = document.cookie.split(";");
for (i of cookies)
/CookieConsent/g.test(i) &&
(document.cookie = i + ";expires=0;path=/");
}, false);
</script>
Change consent expiration date
Finally, you can also reduce the expiration date of the CookieConsent cookie, and update the Cookiebot banner and Cookie Declaration to reflect this reduced lifespan. This script changes the expiration to 6 months instead of the default 12:
<script data-cookieconsent="ignore">
window.addEventListener("CookiebotOnLoad", function (e) {
var cookies = document.cookie.split(";"),
months = 6,
d = new Date();
d.setMonth(d.getMonth() + months);
for (i of cookies)
if (/CookieConsent/g.test(i) && !/reduced:true/.test(i)) {
i = i.substr(0, i.length - 1),
i += "%2Creduced:true}";
document.cookie = i + ";expires=" + d.toUTCString() + ";path=/";
}
},false);
window.addEventListener('CookiebotOnDialogDisplay', function(e) {
var a = "#CybotCookiebotDialogDetailTableNecessary > tbody";
for (i of document.querySelector(a).children)
i.firstElementChild.innerText === "CookieConsent" &&
(i.childNodes[3].innerText = "6 months");
}, false);
window.addEventListener('DOMContentLoaded', function(e) {
var c = document.querySelector(".CookieDeclarationTable tbody").children;
if ("undefined" != typeof CookieDeclaration)
for (i of c)
c[1].firstElementChild.innerText == 'CookieConsent' &&
(c[1].childNodes[7].innerText = "6 months");
}, false);
</script>
Comments
0 comments
Please sign in to leave a comment.