yireo-magento1 / Yireo_GoogleTagManager

Implement Google Tag Manager in Magento 1 (deprecated)
Open Software License 3.0
56 stars 46 forks source link

[feature] event tag datalayer #84

Closed r4y7s closed 6 years ago

r4y7s commented 6 years ago

see #68

one more step in this direction Enhanced Ecommerce UA

jissereitsma commented 6 years ago

This is awesome. I've not used events myself and am using the module (and GTM for that matters) too little to make these steps. I've done a quick code review and it looks solid to me. Thanks!

gety9 commented 6 years ago

@zarapico

Thank you for your PR!

Could you elaborate on "possibility of establishing the name of the event with the code setEcommerceEvent"?

I would like to set-up a custom name for event to be used as a trigger on success page. Right now i see only standard gtm.js, gtm.dom and gtm.load.

I would prefer to use event instead of pageview because "it's best practice to use the dataLayer event instead of the pageview. Why? Because you can ensure that the dataLayer is available at that time. Some more reasons: 1. The pageview can mainly be filtered by URL 2. If you reload the page the pageview trigger would fire the tag again, whereas with the custom event you can build it in to prevent that from happening."

p.s. "auto add purchase in order.phtml" is working correctly > https://puu.sh/zNjp4/21c8ed076b.png just not sure how to set-up event name.

r4y7s commented 6 years ago

@gety9

I think you are looking for this code, on line 32 https://github.com/zarapico/Yireo_GoogleTagManager/blob/82ef8f3af5a92f2ea8071c7c1fda8ea362cbe51f/source/app/design/frontend/base/default/template/googletagmanager/data/quote.phtml#L32

Currently by default the name of the event is established as "checkout" following the example of this guide https://developers.google.com/tag-manager/enhanced-ecommerce#checkout

But you can replace the template "base/default/template/googletagmanager/data/quote.phtml" in your own theme

PS: You may need to check the isCheckoutPage() method if your url is different from the default value. I also recommend this extension https://www.yireo.com/software/magento-extensions/checkout-tester

gety9 commented 6 years ago

@zarapico

Thank you for your reply.

I see now. It sets event name for Google Analytics event, not for GTM event. I was thinking it was setting up GTM event that i can use as a trigger to fire GTM event on success page so i can send purchase datalayer. Now i see that purchase data is send automatically on success page.

One thing i am worried about, if user reloads the page 'ecommerce': {'purchase': { will be sent 2nd time, won't it count as double transaction/conversion?

UPDATE1: I think 'ecommerce': {'purchase': { should be sent once per order, other wise we can get this. More on this here.

UPDATE2: Sending 'ecommerce': {'purchase': { once per order will solve some of the issues, but to solve ones connected with mobile caching, cookie might be needed. More on this here.

r4y7s commented 6 years ago

@gety9

If you are using the standard Magento checkout, you can not reload the success page, since it will be redigned to /checkout/cart/ (with the empty cart) But it depends on the changes you may have in your purchase process

gety9 commented 6 years ago

@zarapico

Interesting, thank you for pointing this out. Seems like we did some customization in success page functionality, will look into that!