Skip to content

Commit 56f094f

Browse files
committed
Allow multiple GTM IDs
1 parent df21430 commit 56f094f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Fixed
99
- Only trigger `view_cart` event when there are items in the cart
10+
- Allow multiple GTM IDs
1011

1112
## [3.9.9] - 22 October 2024
1213
### Fixed

view/frontend/templates/script.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use Yireo\GoogleTagManager2\Config\Config;
66
/** @var Config $config */
77
/** @var Template $block */
88
$config = $block->getConfig();
9+
$gtmIds = explode(',', $config->getId());
910
?>
1011

1112
<?php
@@ -21,6 +22,7 @@ $events = ($config->waitForUserInteraction() === false)
2122
window.removeEventListener(eventType, initYireoGoogleTagManager2);
2223
});
2324

25+
<?php foreach($gtmIds as $gtmId): ?>
2426
(function (w, d, s, l, i) {
2527
w[l] = w[l] || [];
2628
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
@@ -31,6 +33,7 @@ $events = ($config->waitForUserInteraction() === false)
3133
j.src = '<?= $config->getGoogleTagmanagerUrl() ?>' + '/gtm.js?id=' + i + dl;
3234
f.parentNode.insertBefore(j, f);
3335
})(window, document, 'script', 'dataLayer', '<?= $config->getId() ?>');
36+
<?php endforeach; ?>
3437
}
3538

3639
events.forEach(function (eventType) {

0 commit comments

Comments
 (0)