Skip to content

Commit

Permalink
Allow multiple GTM IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Oct 22, 2024
1 parent df21430 commit 56f094f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Only trigger `view_cart` event when there are items in the cart
- Allow multiple GTM IDs

## [3.9.9] - 22 October 2024
### Fixed
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/templates/script.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Yireo\GoogleTagManager2\Config\Config;
/** @var Config $config */
/** @var Template $block */
$config = $block->getConfig();
$gtmIds = explode(',', $config->getId());
?>

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

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

events.forEach(function (eventType) {
Expand Down

0 comments on commit 56f094f

Please sign in to comment.