File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111class Checkout extends Component
1212{
13- protected $ listeners = [
14- 'shipping_method_selected ' => 'triggerShippingMethod ' ,
15- 'payment_method_selected ' => 'triggerPaymentMethod ' ,
16- ];
1713 private CheckoutSession $ checkoutSession ;
1814 private BeginCheckout $ beginCheckout ;
1915 private AddShippingInfo $ addShippingInfo ;
@@ -31,6 +27,17 @@ public function __construct(
3127 $ this ->addPaymentInfo = $ addPaymentInfo ;
3228 }
3329
30+ public function boot (): void
31+ {
32+ $ parent = get_parent_class ($ this );
33+ if ($ parent && method_exists ($ parent , 'boot ' )) {
34+ parent ::boot ();
35+ }
36+
37+ $ this ->listeners ['shipping_method_selected ' ] = 'triggerShippingMethod ' ;
38+ $ this ->listeners ['payment_method_selected ' ] = 'triggerPaymentMethod ' ;
39+ }
40+
3441 public function triggerBeginCheckout ()
3542 {
3643 $ this ->dispatchBrowserEvent ('ga:trigger-event ' , $ this ->beginCheckout ->get ());
Original file line number Diff line number Diff line change 22<page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
33 <body >
44 <referenceContainer name =" main" >
5- <block template =" Tagging_GTM::hyva_checkout/data-layer.phtml"
6- ifconfig =" googletagmanager2/settings/enabled" >
5+ <block name =" yireo_googletagmanager2.hyva_checkout.data-layer.component"
6+ template =" Tagging_GTM::hyva_checkout/data-layer.phtml"
7+ ifconfig =" GTM/settings/enabled"
8+ after =" Tagging_GTM.pusher-script" >
79 <arguments >
810 <argument name =" magewire" xsi : type =" object" >Tagging\GTM\MageWire\Checkout</argument >
911 <argument name =" begin_checkout_event" xsi : type =" object" >Tagging\GTM\DataLayer\Event\BeginCheckout</argument >
Original file line number Diff line number Diff line change @@ -14,26 +14,18 @@ if (false === $magewire->isHyvaCheckoutEnabled()) {
1414}
1515
1616$ beginCheckoutEvent = $ block ->getData ('begin_checkout_event ' );
17+ $ beginCheckoutPayload = $ beginCheckoutEvent ->get ();
1718?>
18- <div>
19+ <div class="hidden" >
1920 <script>
20- function initYireoGoogleTagManagerInHyvaCheckout () {
21+ ( function () {
2122 "use strict";
2223
23- function triggerEvent (event) {
24+ window.addEventListener('ga:trigger-event', function (event) {
2425 googleTagManager2Pusher(event.detail, 'Hyva Checkout');
25- }
26+ }, {passive: true});
2627
27- triggerEvent(new CustomEvent('ga:trigger-event', {detail: <?= json_encode ($ beginCheckoutEvent ->get ()) ?> }));
28-
29- return {
30- triggerEvent
31- }
32- }
28+ googleTagManager2Pusher(<?= /* @noEscape */ json_encode ($ beginCheckoutPayload ) ?> , 'Hyva Checkout');
29+ })();
3330 </script><?php if (isset ($ hyvaCsp ) && $ hyvaCsp ): ?> <?php $ hyvaCsp ->registerInlineScript () ?> <?php endif ; ?>
34- <div id="ga-trigger"
35- x-data="initYireoGoogleTagManagerInHyvaCheckout()"
36- class="hidden"
37- @ga:trigger-event.window="triggerEvent($event)"
38- ></div>
3931</div>
You can’t perform that action at this time.
0 commit comments