What is the best way to add google tag manager to a Magento 1.9.2 store?

I was thinking about putting it in the Magento where the analytics code is located.


It depends upon what do you want to do with GTM. To install you can do that by adding the following piece of code before body end -:

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-ID"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
<!-- End Google Tag Manager -->

But if you want to add data layers then you can do that in different pages for example adding data layer on order confirmation page for purchase event by adding the following code but make sure it executes before GTM default code (as shown above)

<script type="text/javascript">
    window.dataLayer = window.dataLayer || [];
      'ecommerce': {
        'purchase': {
          'actionField': {
            'id': '100000191',                         // Transaction ID. Required for purchases and refunds.
            'affiliation': '',
            'revenue': '199.9900',                     // Total transaction value (incl. tax and shipping)
            'tax': '15.2400',
            'shipping': '0.0000',
            'coupon': ''
          'products': [
            'name': 'AT&T 8525 PDA',     // Name or ID is required.
            'id': '8525PDA',
            'price': '184.7500',
            'brand': 'At&t',
            'category': 'Cell Phones',
            'quantity': 1.0000          }]

You could also use the following plug-in which does help you set up GTM with multiple tracking like Universal Analytics, Enhanced Ecommerce, Facebook Conversion, Google Remarketing etc.


|improve this answer|||||

The tag manager code has to go to the top of the but not in the section. It's probably a good idea to do it with a plugin.

|improve this answer|||||

You can try extension https://marketplace.magento.com/chapagain-chapagain-googletagmanager.html
I am using it in couple of projects.
It is easy to use and customize.

|improve this answer|||||
  • How to use it in the template? There is no example. – Black May 24 '18 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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