I've created google analytics and Google tag manager account to find out all event of product like Add to Cart, Remove Cart, Checkout, Product click, Checkout, Product impression in Google Analytics.

I've created tag and Trgger for that but its not reflecting in Google anaytics.

First i want to display data layer in front end with all products details.

Please tell me how to pass data in data layer.

So i have to put code in core file to get product id, name, price, etc. and pass variable on datapush script as mentioned on this URL.

Or Magento have default functionality for this. only paste the script on header file? to get datalayer in frontend with details

3 Answers 3


Here is the Google Tag Manager module I would recommend for Magento 2 -:


  • Event Category and Label not reflecting in Google Analytics
    – Mahendra
    Commented Jun 26, 2018 at 9:47
  • I installed this plugin but addToCArt, removeFromCart is not reflecting in Google Analytics. What am I missing here? I have also defined Google Analytics from Magento -> Sales -> Google API. I am not sure what am I missing here? I can see transaction data in Google Analytics but could not see add to cart and cart abandoned data Commented Oct 22, 2020 at 6:40
  • This is not an answer Commented Jun 3, 2021 at 14:48

The basic GTM code can be added easily using the following three steps -:

Step 1

gtm_head.phtml ---> YourTheme/Magento_Theme/templates/html/gtm_head.phtml

add the following script:

<!-- Google Tag Manager -->
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
<!-- End Google Tag Manager -->

Step 2

gtm_body.phtml ---> YourTheme/Magento_Theme/templates/html/gtm_body.phtml

add the following script:

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Step 3

default .xml file: --->YourTheme/Magento_Theme/layout/default.xml and add this:

<referenceContainer name="head.additional">
 <block class="Magento\Framework\View\Element\Template" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />

<referenceContainer name="after.body.start">
 <block class="Magento\Framework\View\Element\Template" name="gtm.body" before="-" template="Magento_Theme::html/gtm_body.phtml" />

The above will add basic script of GTM code on your Magento 2 store but GTM is all about data and data layers without them there is very little can be done using the basic script of GTM.

For example - for Google Enhanced Ecommerce, you need to create data layers for all the below actions / pages

If you are a developer you can add the above data layers in your code using the following layout handlers -:

  • default.xml

  • catalog_category_view.xml

  • catalog_product_view.xml

  • catalogsearch_advanced_result.xml

  • catalogsearch_result_index.xml

  • checkout_cart_index.xml

  • checkout_index_index.xml

  • checkout_onepage_success.xml

If not then there are quite few extensions available for small amount to buy. Personally I would recommend the following two extension for M1 and M2

M1 Google Tag Manager with Enhanced Ecommerce

M2 Google Tag Manager with Enhanced Ecommerce


This issue was a real pain. But finally able to resolve this issue by using this plugin (Free Version)

This provide some additional data for Google Analytics and will resolve your problems! Enjoy :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.