Hi @Josef
Before I share, a short notice, that I’ve just tried the code myself on our site and it only disables the embed only if I don’t click any button on the cookie banner, whether it is agreeing or declining, whereas before it was also blocking the embed for me if I clicked “disable analytics”. Maybe something changed in their API or I have confused something, but here is how it was implemented originally.
This code is modified, with added variables. You don’t need to embed this code on each page, just in the custom code in the project settings.
So this goes to your Project Settings - Custom Code - Header
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
This goes to Project Settings - Custom Code - Footer
Make sure to replace ID’s and KEY’s, etc in CAPS with your data.
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
var enableGA = function() {
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'YOUR GOOGLE ANALYTICS ID HERE', 'auto');
ga('send', 'pageview');
};
var renderEventMap = function() {
var $eventMapNode = $('#event-map');
if ($eventMapNode.length) {
var query = $eventMapNode.data('query');
$eventMapNode.replaceWith(
$('<iframe width="100%" height="100%" frameborder="0" style="border:0" allowfullscreen>')
.attr('src', 'https://www.google.com/maps/embed/v1/place?key=YOUR_MAP_KEY_HERE&q=' + query)
);
}
};
var enableCookieConsent = function() {
enableGA();
renderEventMap();
if (window.initFbButton) {
initFbButton();
}
};
window.addEventListener("load", function() {
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#fafafa"
},
"button": {
"background": "#f78f1e",
"text": "#ffffff"
}
},
revokable:true,
"theme": "classic",
"type": "opt-in",
"content": {
"message": "We use cookies to provide you best experience on our website. We also use Google analytics for our internal statistics. You may choose to disable analytics if you prefer.",
"dismiss": "Disable analytics",
"allow": "Got It!",
"link": "Learn More",
"href": "LINK_TO_YOUR_PRIVACY_POLICY"
},
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
enableCookieConsent();
}
if (type == 'opt-out' && !didConsent) {
// disable cookies
// NOTHING TO DO
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
enableCookieConsent();
}
if (type == 'opt-out' && !didConsent) {
// disable cookies
// NOTHING TO DO
}
},
onRevokeChoice: function() {
var type = this.options.type;
if (type == 'opt-in') {
// disable cookies
// NOTHING TO DO
}
if (type == 'opt-out') {
// enable cookies
enableCookieConsent();
}
}
}, function (popup) {
$('#revoke-cc-btn').on('click', function() {
popup.revokeChoice();
});
})
});
</script>
In my particular case it is a google map embed which I am placing on a dynamic page template, it is showing the address on a map which is being taken from the dynamic field in my collection.
So you place this within a code embed on your static or dynamic page. If you don’t need a search query, I believe you can just remove the data-query class altogether and replace the iframe with your particular iframe in the project settings script.
It is easy to check if it is working or not, if you do not agree to cookies, you should not see your map embed.
CORRECTION Also this code has a revoke button support, so you can place a default Webflow button on any page and give it an ID revoke-cc-btn
Additionally it disables any facebook buttons if they are placed on the site, since I figured it was also pulling some analytics, if that is not needed, I believe you can just remove this bit
if (window.initFbButton) {
initFbButton();
}