I just want to ask the community, how to you deal with cookie consent, consent mode v2 by google and GDPR in general.
I am currently working on a project where I use the gtag and as far as I know there is no real consent banner available that is not a paid plan. I found this: Cookie Consent by orestbida github.
May someone what to share their experience and the tools you work with.
Setup default consent state in header, before GTM tag - if the consent is granted default state is granted:
<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
let data = {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
}
{% if sgCookies['analytics'] %}
data['analytics_storage'] = 'granted';
data['ad_storage'] = 'granted';
{% endif %}
{% if sgCookies['marketing'] %}
data['ad_storage'] = 'granted';
data['ad_user_data'] = 'granted';
data['ad_personalization'] = 'granted';
{% endif %}
{% if sgCookies['ad'] %}
data['ad_storage'] = 'granted';
data['ad_user_data'] = 'granted';
{% endif %}
gtag('consent', 'default',data);
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
And I added this small javascript to setup google consent v2:
I tried to use the small gdpr banner. But i use UIkit 3 as CSS Framework and I can’t seem to get it run. If I copy the components from the plugin folder to my partial theme folder, the plugin is not loading. Do you have also such experiences?
Its a little bit complicated, because the plugin uses bootstrap as css framework. I am using bulma css framework, so I hardcoded the plugin file with the my styles - I know, its not the correct way it should be done, it will overwrite my changes after plugin update, but for me it was the fastest solution for now.
For better solution I’ve recommend to use this plugin with raw html option and create custom css styles/custom js functions to meet your requirements.