Skip to content

Commit 16c791d

Browse files
committed
Merge branch 'master' of github.com:yireo/Yireo_GoogleTagManager2
2 parents 57569f3 + c406aa8 commit 16c791d

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

MageWire/Checkout.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public function __construct(
2323
$this->addPaymentInfo = $addPaymentInfo;
2424
}
2525

26-
public function booted(): void
26+
public function boot(): void
2727
{
2828
// @phpstan-ignore-next-line
29-
parent::booted();
29+
parent::boot();
3030

3131
// @todo: Do this only with the Hyva Checkout
3232
// @phpstan-ignore-next-line
3333
$this->listeners['shipping_method_selected'] = 'triggerShippingMethod';
34-
$this->listeners['payment_method_selected'] = 'triggerShippingMethod';
34+
$this->listeners['payment_method_selected'] = 'triggerPaymentMethod';
3535

3636
// @todo: Do this only with the Loki Checkout
3737
$this->listeners['afterSaveShippingMethod'] = 'triggerShippingMethod';
38-
$this->listeners['afterSavePaymentMethod'] = 'triggerShippingMethod';
38+
$this->listeners['afterSavePaymentMethod'] = 'triggerPaymentMethod';
3939
}
4040

4141
public function triggerShippingMethod()

view/frontend/templates/hyva/script-pusher.phtml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
99
*/
1010
?>
1111
<script>
12-
function yireoGoogleTagManager2Pusher(eventData, message) {
12+
function yireoGoogleTagManager2Pusher(eventData, message, callback) {
1313
window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS = window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS || [];
1414

15+
function doCallback(cb) {
16+
if (undefined === cb) {
17+
return;
18+
}
19+
20+
cb();
21+
}
22+
23+
1524
const copyEventData = Object.assign({}, eventData);
1625
let metaData = {};
1726
if (copyEventData.meta) {
@@ -22,12 +31,14 @@
2231
const eventHash = btoa(encodeURIComponent(JSON.stringify(copyEventData)));
2332
if (window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS.includes(eventHash)) {
2433
yireoGoogleTagManager2Logger('Warning: Event already triggered', eventData);
34+
doCallback(callback);
2535
return;
2636
}
2737

2838
if (metaData && metaData.allowed_pages && metaData.allowed_pages.length > 0
2939
&& false === metaData.allowed_pages.some(page => window.location.pathname.includes(page))) {
3040
yireoGoogleTagManager2Logger('Warning: Skipping event, not in allowed pages', window.location.pathname, eventData);
41+
doCallback(callback);
3142
return;
3243
}
3344

@@ -42,7 +53,13 @@
4253
window.dataLayer.push({ecommerce: null});
4354
}
4455

45-
window.dataLayer.push(eventData);
46-
window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS.push(eventHash);
56+
try {
57+
window.dataLayer.push(eventData);
58+
window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS.push(eventHash);
59+
} catch(error) {
60+
doCallback(callback);
61+
}
62+
63+
doCallback(callback);
4764
}
4865
</script>

0 commit comments

Comments
 (0)