Google Tag Manager Magento 2

How to Add Google Tag Manager to Magento 2?

Today, we’re going to teach you guys how to add Google Tag Manager to your Magento 2 store.

Google Tag Manager is basically a tag management system by Google that allows you to update your measurement codes easily and quickly.

In other words, the Google Tag Manager gives you the ability to add as well as update your tags for remarketing, conversion monitoring, website analytics, and much more.

There are, in fact, limitless ways you can use Google Tag Manager to monitor activity on your website or eCommerce store.

And in this post, we’re going to show you exactly how you can add Google Tag Manager to your Magento 2 store.

Method to Add Google Tag Manager to Magento 2 Store

In Magento 2, you can easily add the Google Tag Manager without any need for a third-party extension.

To add Google Tag Manager to your Magento 2 store, all you need to do is add your unique Google Tag Manager code to your theme.

The Google Tag Manager code is divided into two parts – Script & NoScript.

You need to put these code snippets into two separate phtml template head and body files as shown below.

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

<script>..</script> <!-- GTM code -->

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

<noscript>..</noscript> <!-- GTM code -->

Now, we also need to load these files correspondingly through the default default.xml file.

<!-- YourTheme/Magento_Theme/layout/default.xml -->

<referenceContainer name="head.additional">

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

</referenceContainer>

<referenceContainer name="after.body.start">

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

</referenceContainer>

Your Google Tag Manager code is finally added and now you can set up your Google Analytics for monitoring and reporting of your Magento 2 store.

Final Note

And there you go!

This is the easiest way to add Google Tag Manager to your Magento 2 store.

If you want to do it without adding code you can use Magento 2 GA4 with GTM Extension from MageDelight.

Also, Refer this Magento 2 Google Analytics 4 (GA4) With GTM Support Extension’s FAQ Page for most common questions and it’s answers.

And if you need our professional assistance, feel free to contact us anytime.