1

I want to add (GTM) google tag manager in my Magento 2 store, but without installing any extension.

Please help me out that how I can add CTM manually.

2 Answers 2

2

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.

1

Open your Magento Admin Panel and move to Content > Design > Configuration > Edit the Store View > Other Settings> HTML Head.

Paste the code you got from GTM for the tag here.

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.