Nowadays, to run a successful online store, merchants need to understand customers’ preferences and tastes. And tools like GTM make it easier to collect this kind of data, which merchants can use to improve conversions and optimize marketing efforts without touching a line of code.
In this guide, we’ll go through how to install and configure Google Tag Manager in Magento 2, and how to start tracking key events.
Why Use Google Tag Manager in Magento 2?
Before jumping into the setup, let’s see which benefits GTM offers to your Magento store:
Advanced Analytics & Insights
With the help of GTM, merchants can integrate tools like GA4 and Google Ads into their store to receive a full funnel view of customer behaviour.
Easy Tracking Without Code Changes
GTM lets merchants add and update tracking without redeploying the site for every tracking tweak. Therefore, it offers faster updates and experimentation.
Enhanced Ecommerce Tracking
With GTM, merchants can track which products perform best, identify cart abandonment points, and investigate user journeys across pages, not to mention its ability to aggregate data from different devices and browsers.
How to Install the Google Tag Manager Script?
To add GTM to Magento, without any extensions you need to install the GTM script into your theme.
For this, navigate to Magento Admin > Content > Design > Configuration and paste the GTM script inside the Head > Scripts and Style Sheets section of a specific theme. Don't forget to Save the config.
Note: this installs the GTM container, but doesn’t configure tracking tags, triggers and variables yet.
If you prefer a more technical approach, place the GTM code directly into your theme’s head and body sections using .phtml files.
As soon as you install the GTM script, Magento will trigger the GTM script.
The next step is to set up GTM events (tags, triggers, and variables) separately.
How to Add GTM to Magento Using an Extension?
The easiest way to add Google Tag Manager to Magento is by using an extension, like Magefan Google Tag Manager.
Extensions come with pre-built data layers for all important eCommerce events and connect to Google Analytics automatically.
This way, you don't have to edit the script, work with code, set up GA4 separately, or even create GTM tags.
Here are the general steps to make it work in your Magento store:
Step 1: Create a GTM account and set up a container for your store
Step 2: Copy your GTM account, container, and public IDs from the GTM dashboard
Step 3: Open Google Analytics 4 and copy the Measurement ID of your property
Step 4: Go to Magento admin and paste GTM IDs into the corresponding configuration fields
Step 5: Create GTM tags by importing the data layer
Step 6: Use the GTM preview mode to check if everything works properly
Step 7: Publish GTM tags to activate tracking on your store
Once the GTM tags are published, you can go to the GA4 > Reports > Realtime and monitor the activity on your website.
Adding Google Tag Manager to Magento 2 is a crucial step toward better analytics and smarter decision-making.
However, consider setting up the GTM extension if you want to avoid manual configuration, reduce the risk of errors, and speed up the implementation process.
It can help streamline tracking setup, especially when working with events, data layers, and integrations with tools like Google Analytics 4.
Top comments (0)