If you want your cookie notice to only appear once every 24 hours per user, you can utilize browser cookies to save the user's consent data. Here is a guide on how you can set this up:
Once the user agrees to the cookie notice, create a cookie in their browser that expires after 24 hours from the current time.
Upon the user's return to your site, check for the presence of the cookie and ensure it has not yet expired. If the cookie is present and valid, refrain from displaying the notice again. Otherwise, show the notice as needed.
function setCookie(name, value, hours) {
var expires = "";
if (hours) {
var date = new Date();
date.setTime(date.getTime() + hours * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function displayCookieNotice() {
var cookieNotice = document.getElementById("cookie-banner");
if (getCookie("cookieConsent") === null) {
cookieNotice.style.display = "block";
} else {
cookieNotice.style.display = "none";
}
}
function agreeToCookies() {
setCookie("cookieConsent", "true", 24);
document.getElementById("cookie-banner").style.display = "none";
}
window.onload = function() {
displayCookieNotice();
};