Summary
We have a Magento 2 store that we are having trouble setting up Google Analytics to track eccommerce correctly.
We have followed the Magento docs for setting up GA & GTM, but it is not collecting the correct amount of Sessions with Add to Basket in the Conversions > Ecommerce > Shopping Behavior.
From the image above you can see that it is not tracking the sessions correctly. 27 Sessions with Checkout but only 1 Session with Add to Basket, this does not add up, a user must add to cart before getting to the checkout.
Also, when I check the no of orders on Magento I see there are actually 29 orders, 27 of which are from different users. So it seems it’s not capturing the number of orders correctly too.
Debugging/Setup
We followed the Magento docs for setting up GA & GTM as I show below. If you click on an image below you should see a better quality one.
We have E-commerce setup in GA:
At first I discovered with the GTM preview mode that the addToCart tag which was set up with the recommended Magento configuration was not firing. It seems the data layer event was not firing for the GTM trigger.
So I set up a new trigger which fired on Click and added it to the :
I can now see the tag firing in GTM preview mode:
And I can see the Add to Cart event in GAs Real-time Event report.
But still it’s not showing the correct data in the Sessions with Add to Basket in the Conversions > Ecommerce > Shopping Behavior.
Questions
- What could I be missing?
- Should I set Non-Interaction Hit to false in the GTM tag setting?
- Should I set use data layer to false for the tag in GTM, as the
addToCart custom event is not firing? Or maybe this is still needed
for something. - Any tips on how I can debug why the addToCart custom event is nor
firing on Magento while GTM is in preview mode? I noted that the session in Magento is 3.5 hours, while in GA the Session timeout is only 30min. Perhaps this could be it?we changed the GA session timeout to match Magento’s, and this was not it 🙁
Thank you in advance, any help appreciated 🙂
2
Answers
Based on the comment from @lossleader to my question, I was able to identify and fix the issue. I'll answer it here in case anyone else finds it helpful.
Basically as @lossleader said in his comment the main thing is:
So triggering the addToCart tag with a simple click event is not enough as it does not contain the e-commerce data, I needed to fix how the enhance ecommerce addToCart event was triggered on Magento.
I discovered that Magento Commerce changed/fixed how they end up calling the function which trigger this event in recent upgrades, i.e. commit MAGETWO-69210 & commit MAGETWO-87437
Our Magento did receive these changes as the list.phtml template and the catalog-add-to-cart.js file were being overridden in it's theme.
Updating the theme files as the below diff shows resolved the issue in our case:
The custom event that was pushed should also have contained the e-commerce data referred to in the “use dataLayer” tag, so you really needed to fix the magento configuration or detection of the user action rather than emulate it. I.e. look for customizations to the store’s html around these inputs/forms and try reverting them to stock.
It looks like you found the complete answer by looking into updates to magento for the
addToCart
event that were being overridden by the installed theme.