From b4289ce20ed9a12ae264d289bf02dbf0f571ff98 Mon Sep 17 00:00:00 2001 From: Jisse Reitsma Date: Thu, 29 Aug 2024 16:35:06 +0200 Subject: [PATCH] Only clean dataLayer.ecommerce, if new push actually contains ecommerce data --- CHANGELOG.md | 4 ++++ composer.json | 2 +- view/frontend/templates/hyva/script-pusher.phtml | 6 +++++- view/frontend/web/js/push.js | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8646d6d4..4c30d160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.9.7] - 29 August 2024 +### Fixed +- Only clean dataLayer.ecommerce, if new push actually contains ecommerce data + ## [3.9.6] - 23 August 2024 ### Fixed - Move CSP logic to external module `Yireo_CspUtilities` diff --git a/composer.json b/composer.json index 1f171c16..459ac02f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yireo/magento2-googletagmanager2", - "version": "3.9.6", + "version": "3.9.7", "license": "OSL-3.0", "type": "magento2-module", "homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2", diff --git a/view/frontend/templates/hyva/script-pusher.phtml b/view/frontend/templates/hyva/script-pusher.phtml index ba1a3e2a..3216ba15 100644 --- a/view/frontend/templates/hyva/script-pusher.phtml +++ b/view/frontend/templates/hyva/script-pusher.phtml @@ -37,7 +37,11 @@ yireoGoogleTagManager2Logger(message, eventData); window.dataLayer = window.dataLayer || []; - window.dataLayer.push({ecommerce: null}); + + if (eventData.ecommerce) { + window.dataLayer.push({ecommerce: null}); + } + window.dataLayer.push(eventData); window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS.push(eventHash); } diff --git a/view/frontend/web/js/push.js b/view/frontend/web/js/push.js index e531871d..89fca82f 100644 --- a/view/frontend/web/js/push.js +++ b/view/frontend/web/js/push.js @@ -32,7 +32,11 @@ define(['yireoGoogleTagManagerLogger'], function (logger) { logger(message, eventData); window.dataLayer = window.dataLayer || []; - window.dataLayer.push({ecommerce: null}); + + if (cleanEventData.ecommerce) { + window.dataLayer.push({ecommerce: null}); + } + window.dataLayer.push(cleanEventData); window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS.push(eventHash); };