Open schmitch opened 1 week ago
I also found another problem that if I press "Accept All" gtm correclty works when using consentModeHandler: 'gtag'
however when putting it behind a category and going into the settings and only activate a single option it won't set the consent of gtag correctly.
what works is to always run:
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
const defaultSettings = {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
};
if (localStorage.getItem('consentMode') === null) {
gtag('consent', 'default', defaultSettings);
} else {
gtag('consent', 'default', {
...defaultSettings,
...JSON.parse(localStorage.getItem('consentMode')),
});
}
</script>
and put:
(function (w, d, s, l, i) {
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-ID');
into its own script block.
I created a fork where I actually add the support for multiple categories in a dirty way: https://github.com/brainsum/cookieconsent/compare/master...envisia:cookieconsent:schmitch/fixed-cookie-consent
and also fixed the save dialog (which I can probably provide a fix if needed?)
Hello is there a guide how to integrate something like the example page with google tag manager where I have one script tag but multiple categories?
i.e. does this work:
and will it block the script tag only if one of them has no consent?
In the example Page it is always
script
however I do not want to loadgoogletagmanager
by default, only if either category is set. something like: https://github.com/brainsum/cookieconsent/blob/master/docs/index.html#L183 just with the following script tag:whats even more wierd, that the script will only fire if "all" consent is given?
Edit: it looks like the save button does not work, when
wanted
defaults to false, I need to click multiple times........