From 1c85e9564fbafadad4fc5ca3c007bdb733fbb506 Mon Sep 17 00:00:00 2001 From: Victor Kloeppel Date: Tue, 26 May 2026 13:29:35 +0200 Subject: [PATCH] fix for user data script --- .../templates/hyva_checkout/data-layer.phtml | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/view/frontend/templates/hyva_checkout/data-layer.phtml b/view/frontend/templates/hyva_checkout/data-layer.phtml index fc019642..e2ecef53 100644 --- a/view/frontend/templates/hyva_checkout/data-layer.phtml +++ b/view/frontend/templates/hyva_checkout/data-layer.phtml @@ -25,7 +25,38 @@ $beginCheckoutPayload = $beginCheckoutEvent->get(); googleTagManager2Pusher(event.detail, 'Hyva Checkout'); }, {passive: true}); - googleTagManager2Pusher(, 'Hyva Checkout'); + const beginCheckoutPayload = ; + + function userDataAlreadyPushed() { + if (!Array.isArray(window.dataLayer)) { + return false; + } + return window.dataLayer.some(function (entry) { + return entry && entry.event === 'trytagging_user_data'; + }); + } + + function pushBeginCheckout() { + googleTagManager2Pusher(beginCheckoutPayload, 'Hyva Checkout'); + } + + function waitForUserData(maxWaitMs) { + const start = Date.now(); + const interval = setInterval(function () { + if (userDataAlreadyPushed() || Date.now() - start >= maxWaitMs) { + clearInterval(interval); + pushBeginCheckout(); + } + }, 50); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', function () { + waitForUserData(2000); + }); + } else { + waitForUserData(2000); + } })(); registerInlineScript() ?>