yireo / Yireo_GoogleTagManager2

Open Software License 3.0
148 stars 76 forks source link

Hyvä: Empty Ecommerce Push On Checkout Success #244

Closed sprankhub closed 3 months ago

sprankhub commented 3 months ago

When using Hyvä / Hyvä Checkout, the ecommerce property on the data layer will be empty on checkout success. The reason is this line:

https://github.com/yireo/Yireo_GoogleTagManager2/blob/17efb919fb02fe4145b9f7e0eb42f1240f56904c/view/frontend/templates/hyva/script-pusher.phtml#L40

First, the correctly filled ecommerce property will be pushed. But directly afterwards, through the script-additions.phtml, an empty ecommerce property will be pushed overriding the previous (correct) property:

image

So the initial push together with the purchase event is correct. However, on the next, unrelated push to the data layer, the ecommerce property will be reset to null. This is also why in this specific example, the "val" and "oid" parameters in the tracking call are wrong (last line in the screenshot).

I could of course send a PR removing the line, but I guess it is there for a reason. How can this be solved properly? Thanks @jissereitsma in advance!

By the way, the code is almost the same in Luma, so the issue might exist there as well.

jissereitsma commented 3 months ago

Wow, this would be a huge bug. Cleaning the ecommerce property is still recommended by Google. However, it makes sense only if the new data that is being pushed actually contains the same ecommerce property. And with the regular page attributes this is not the case.

I'm releasing right away a new version 3.9.7 with - what I think - is the proper fix.

In my defense :) I've tested this earlier with the GTM Preview Mode and did see the purchase event coming in - even better, it was pushed to GA. However, I think this really relies upon how fast the local dataLayer is synced with GTM.

sprankhub commented 3 months ago

This indeed fixes the issue. Thanks for your fast fix!