Popup cookie not working

I am using the following code to stop my GDPR popup not reappearing after the user clicks accept.

Any ideas why the popup reappears on refresh/navigating to another page.

I placed it in site-wide custom code, and wrapped in script tags.

var popup = document.getElementById(‘consentPopup’);
var alreadyLoaded = window.localStorage.getItem(‘fbGrantConsent’) === ‘true’;

//Show the consent banner if consent is not granted, hide it if consent is already granted.
if (alreadyLoaded) {
popup.style.display = ‘none’;
} else {
popup.style.display = ‘flex’;
}

//Grant consent and store it in localStorage of the browser
var consentBtn = document.getElementById(‘consentBtn’);
consentBtn.addEventListener(“click”, function() {
fbq(‘consent’, ‘grant’);
window.localStorage.setItem(‘fbGrantConsent’, ‘true’);
});

1 Like

Anyone with a tip on this?