Skip to content

Commit 2db0ace

Browse files
committed
Google consent mode v2 compliance
1 parent d92d370 commit 2db0ace

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

view/frontend/templates/js_code.phtml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (!isset($escaper)) {
3131
<?php } ?>
3232

3333
<?php if ($block->isProtectCustomerDataEnabled()) { ?>
34-
document.addEventListener('DOMContentLoaded', function () {
34+
(function () {
3535
function getCookieValue(cookieName) {
3636
let name = cookieName + '=';
3737
let cookieSplit = document.cookie.split(';');
@@ -75,7 +75,7 @@ if (!isset($escaper)) {
7575
mfLoadGtm();
7676
}, 1000);
7777
}
78-
});
78+
})();
7979

8080
<?php } else { ?>
8181
window.mfGtmUserCookiesAllowed = true;
@@ -90,6 +90,16 @@ if (!isset($escaper)) {
9090
if (window.mfGTMTriedToLoad) return;
9191
window.mfGTMTriedToLoad = true;
9292

93+
<?php if ($block->isProtectCustomerDataEnabled()) { ?>
94+
function gtag() { dataLayer.push(arguments); };
95+
gtag('consent', 'update', {
96+
ad_user_data: 'granted',
97+
ad_personalization: 'granted',
98+
ad_storage: 'granted',
99+
analytics_storage: 'granted'
100+
});
101+
<?php } ?>
102+
93103
<?php if ('use_public_id' === $block->getConfig()->getInstallGtm()) { ?>
94104
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
95105
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],

0 commit comments

Comments
 (0)