@@ -13,9 +13,63 @@ if (!isset($escaper)) {
1313}
1414?>
1515<!-- Google Tag Manager -->
16- <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
17- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
18- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
19- 'https:<?= '/ ' . '/ ' ?> www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
20- })(window,document,'script','dataLayer','<?= $ escaper ->escapeHtml ($ block ->getPublicId ()) ?> ');</script>
21- <!-- End Google Tag Manager -->
16+ <script>
17+ function mfLoadGtm() {
18+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
19+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
20+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
21+ 'https:<?= '/ ' . '/ ' ?> www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
22+ })(window,document,'script','dataLayer','<?= $ escaper ->escapeHtml ($ block ->getPublicId ()) ?> ');
23+ }
24+
25+ <?php if ($ block ->isProtectCustomerDataEnabled ()) { ?>
26+ document.addEventListener('DOMContentLoaded', function () {
27+ function getCookieValue(cookieName) {
28+ let name = cookieName + '=';
29+ let cookieSplit = document.cookie.split(';');
30+
31+ for (let i = 0; i < cookieSplit.length; i++) {
32+ let a = cookieSplit[i];
33+
34+ while (a.charAt(0) === ' ') {
35+ a = a.substring(1);
36+ }
37+
38+ if (a.indexOf(name) === 0) {
39+ return a.substring(name.length, a.length);
40+ }
41+ }
42+ return '';
43+ }
44+
45+ function customerDataAllowed() {
46+ let cookie = getCookieValue(
47+ '<?= $ escaper ->escapeHtml (\Magento \Cookie \Helper \Cookie::IS_USER_ALLOWED_SAVE_COOKIE ) ?> '
48+ );
49+ if (cookie) {
50+ cookie = JSON.parse(decodeURIComponent(cookie));
51+ if (cookie[<?= $ escaper ->escapeHtml ($ block ->getWebsiteId ()) ?> ]) {
52+ return true;
53+ }
54+ }
55+
56+ return false
57+ }
58+
59+ if (customerDataAllowed()) {
60+ mfLoadGtm();
61+ } else {
62+ let interval = setInterval(function () {
63+ if (!customerDataAllowed()) return;
64+ clearInterval(interval);
65+ mfLoadGtm();
66+ }, 1000);
67+ }
68+ });
69+
70+ <?php } else { ?>
71+ mfLoadGtm();
72+ <?php } ?>
73+
74+ </script>
75+ <!-- End Google Tag Manager -->
0 commit comments