yireo/Yireo_GoogleTagManager2

Set up consent mode

Opened this issue · 1 comments

To setup a consent solution on a webshop and integrate consent mode (AKA cookie banner) a default consent mode should be setup. I think it can be added in script.phtml so that easy integration with a custom cookie banner can be added.

Would it be beneficial to update the script.phtml file like described here: https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#implementation_example

events.forEach(function (eventType) {
window.removeEventListener(eventType, initYireoGoogleTagManager2);
});

// 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
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});

(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 = '<?= $config->getGoogleTagmanagerUrl() ?>' + '/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '<?= $config->getId() ?>');

I could add a PR for this.

There is a pull-request open that will add a consent popup/banner here: #198
Is this something that will solve your problem?