How To Install Google Tag Manager In Magento 2

Tracking user behavior is essential for any eCommerce store. With Google Tag Manager, you can manage all tracking codes from one dashboard—without editing code every time.

In this guide, you’ll learn how to install Google Tag Manager in Magento 2 using two methods:

  1. Using Magento Admin Panel (recommended)
  2. Adding code to theme files (developer method)

What Is Google Tag Manager?

Google Tag Manager (GTM) is a free tool from Google that helps you manage:

  • Google Analytics
  • Google Ads tracking
  • Facebook Pixel
  • Custom scripts

Instead of changing website code, you control everything inside GTM.

Why Use Google Tag Manager in Magento 2?

When you install Google Tag Manager in Magento 2, you can:

  • Track add-to-cart, checkout, and purchases
  • Improve marketing campaigns
  • Reduce technical work
  • Manage all tags from one place

Steps To Install Google Tag Manager In Magento 2

Create a GTM Account

1. Go to Google Tag Manager

2. Click on Start for free and log in using your Gmail account

3. Click Create Account

4. Enter your info:

  • Account name
  • Container name (your domain)
  • Platform: Web

5. After creating, you’ll get tutorial popup like:

Method 1 (Recommended): Install Google Tag Manager via Admin Panel

Add GTM Code in HTML Head

1. Log in to Magento Admin

2. Go to Content > Design > Configuration

3. Find your active store view

4. Click Edit

5. Scroll to Other Settings

6. Open HTML Head

7. In Scripts and Style Sheets, paste section 1 from GTM tutorial popup:

8. Click Save Configuration.

Add Noscript Code (Optional but Recommended)

Still in the same page:

Go to Other Settings > Footer > Miscellaneous HTML

Paste section 2 from GTM tutorial popup

Click Save Configuration.

Clear Cache And Verify Installation

1. Go to System > Cache Management > Flush Magento Cache to clear cache.

2. Open your website, press F12 → Network tab, search for gtm.js or use GTM Preview Mode

If GTM loads, you successfully install Google Tag Manager in Magento 2.

Method 2: Install Google Tag Manager via Theme Files

This method is for developers who want full control.

Backup Your Website

Always backup files and database before editing code.

Add GTM in <head>

Create or edit:

app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml

Add:

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

Create:

Magento_Theme/templates/gtm_head.phtml

Paste section 1 from GTM tutorial popup to this file.

Add Noscript After <body>

Create:

Magento_Theme/templates/gtm_body.phtml

Paste section 2 from GTM tutorial popup to this file.

Deploy and Clear Cache

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:flush

Common Mistakes

  • Using wrong GTM ID
  • Forgetting to clear cache
  • Pasting code in CMS pages
  • Editing core Magento files

Always use Admin Panel or custom theme.

Final Thoughts

The best way to install Google Tag Manager in Magento 2 is through the Admin Panel because:

  • No coding needed
  • Safe for beginners
  • Easy to maintain

If you need advanced tracking, use the theme file method. Either way, once GTM is installed, you can manage all tracking from one place and grow your store more effectively.

5 2 votes
Article Rating
Aaron LX

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x