We’re using the CookieYes template in GTM, and have checked/double checked the website key is entered as per the instructions provided by CookieYes.
The web dev has removed the wordpress plugin, and removed additional code relating to cookies.
What am I missing? #Stumped
@cookieyesteam
<div id="cookie-consent-banner" class="cookie-consent-banner">
<h3>Deze website maakt gebruik van cookies</h3>
<p>Deze website gebruikt cookies om uw gebruikerservaring te verbeteren. Door onze website te gebruiken, stemt u in met alle cookies in overeenstemming met ons Cookiebeleid.</p>
<button id="btn-accept-all" class="cookie-consent-button btn-success">Alles accepteren</button>
<button id="btn-accept-some" class="cookie-consent-button btn-outline">selectie accepteren</button>
<button id="btn-reject-all" class="cookie-consent-button btn-grayscale">Alles afwijzen</button>
<div class="cookie-consent-options">
<label><input id="consent-necessary" type="checkbox" value="Necessary" checked disabled>Noodzakelijk</label>
<label><input id="consent-analytics" type="checkbox" value="Analytics" checked>Statistieken</label>
<label><input id="consent-preferences" type="checkbox" value="Preferences" checked>Voorkeuren</label>
<label><input id="consent-marketing" type="checkbox" value="Marketing">Marketing</label>
</div>
</div>
I’ve placed the following code in my header.php:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
if(localStorage.getItem('consentMode') === null){
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied',
'personalization_storage': 'denied',
'functionality_storage': 'denied',
'security_storage': 'denied',
});
} else {
gtag('consent', 'default', JSON.parse(localStorage.getItem('consentMode')));
}
</script>
And the following code in my functions.php
function enqueue_cookie_bar_script() {
wp_enqueue_script('cookie-bar-script', get_template_directory_uri() . '/cookiebar2.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'enqueue_cookie_bar_script', 15);
This is the cookiebar2.js file, which is executed. in the console I can see the ‘script started’ but somehow, it is not executing the ‘addEventListerners’ when clicking the buttons. When clicking a button it is closing the popup (so the jQuery part at the bottom is working) but the consent items aren’t updated. Does someone know why this isnt working? Hope someone can help me!
document.addEventListener('DOMContentLoaded', function () {
console.log("script started");
function hidePopup() {
// document.getElementById('cookie-consent-banner').style.display = 'none';
elementorProFrontend.modules.popup.closePopup({}, event)
}
document.getElementById('btn-accept-all').addEventListener('click', function () {
console.log("btn clicked");
setConsent({
necessary: true,
analytics: true,
preferences: true,
marketing: true
});
hidePopup();
});
document.getElementById('btn-accept-some').addEventListener('click', function () {
setConsent({
necessary: true,
analytics: document.getElementById('consent-analytics').checked,
preferences: document.getElementById('consent-preferences').checked,
marketing: document.getElementById('consent-marketing').checked
});
hidePopup();
});
document.getElementById('btn-reject-all').addEventListener('click', function () {
setConsent({
necessary: false,
analytics: false,
preferences: false,
marketing: false
});
hidePopup();
});
function setConsent(consent) {
console.log("consent is going to be set");
const consentMode = {
'functionality_storage': consent.necessary ? 'granted' : 'denied',
'security_storage': consent.necessary ? 'granted' : 'denied',
'ad_storage': consent.marketing ? 'granted' : 'denied',
'analytics_storage': consent.analytics ? 'granted' : 'denied',
'personalization': consent.preferences ? 'granted' : 'denied',
};
gtag('consent', 'update', consentMode);
localStorage.setItem('consentMode', JSON.stringify(consentMode));
};
jQuery(document).ready(function ($) {
$(document).on('click', '.cookie-consent-button', function (event) {
elementorProFrontend.modules.popup.closePopup({}, event);
});
});
});
]]>OR Is it just a warning and it’s assumed that since they stay on the site they at least have been warned and if they are not ‘ok’ with it then they don’t have to be on your site? Is that how it is?
Some explanation of this would be great, thank you! Luv the plugin!
Any help appreciated!
]]>I’d like to know how to exactly set the consent box? How does it really works? I’d like to know how can I block my scripts when users do not accept the consent box. I think I miscofigured mine because my script (newsletter bar) still appears even users don’t accept the cookie consent box. Please let me know how to set it right..
Hee’s a shot from my settings: https://prntscr.com/kownis
Another thing. Where can I actually get my code snippet for Google Analytics? Thank you!
Best regards
]]>