Running a Magento store successfully depends not only on the products you’re selling but also on the marketing strategies you’ve applied and the tools you used for data analysis to understand your customer’s behavior and journey better.
Regarding data analysis, Google provides tools that ensure accurate tracking and monitoring of your Magento store. These tools include Google Analytics and Adwords, which you can easily integrate via Magento 2 Google Tag Manager.
This extension allows Magento store owners and marketers to track conversions quickly, store analytics, remarketing/retargeting, and related functionalities through a single line of code placed on their Magento 2 stores.
In this article, I will explain why you should use Google Tag Manager and how to set up and configure it on your Magento store.
Google Tag Manager Overview
Google Tag Manager is an accessible, reliable, and integrated tag management system that is useful for quickly managing tags on a user interface without writing a new piece of code fragments each time.
When you set up GTM, you configure various triggers associated with different conversion events on your site. When those events happen, the GTM code “fires,” and the event is registered and can be tracked using Google Analytics.
You can track just about any kind of behavior in GTM, like
- Link clicks
- File downloads
- Adding products to the cart
- Removing products from the cart
- Form or cart abandonment
- Video plays and more
- Tracking which article elements get the most conversion or longest time on page
Magento 2 Google Tag Manager gives you far more control if you want to track a wide range of specific events to better understand.
Google Tag Manager Requirements
A Magento built-in GTM module is now available starting from Magento Adobe Commerce 2.4.5. Knowing that the Google Tag Manager built-in version is received in the enterprise edition, the Magento open-source store owners could still connect to the Google Tag Manager with a third-party solution.
Note: Google Analytics 4 will replace Universal Analytics on July 1, 2023.
Method 1: Add Google Tag Manager in Magento 2 (Default)
When it comes to Magento 2, store owners implement the google tag manager to manage and analyze user’s activity with marketing tags. To make the process easier without needing technical knowledge, let’s start with simple steps to add google tag manager in magento 2.
- Step 1: Log in to your Google Tag Manager account and create a new account if you don’t already have one.
- Step 2: Set the Account Name and select Country.
- Step 3: Specify the Container name, a descriptive title used to associate the container with your website, and select Web for a Target Platform.
- Step 4: Get the GMT codes you need to add to every website page — in <head> and <body>.
- Step 5: Log in to your Magento 2 admin panel, navigate to Content → Design → Configuration, and select the website to which you need to apply the GTM code.
- Step 6: Go to the HTML Head section and paste the code for the <head> in the Scripts and Style Sheets field.
- Step 7: Move to the Footer section on the same page and insert the <body> code in the Miscellaneous HTML field.
- Step 8: Remember to Save Config and clean the Magento cache for applying changes.
How to Check GTM on Your Store?
To check if the GTM code is configured correctly to your store page, press Ctrl+U and view the source code.
Method 2: Add Google Tag Manager in Magento 2 (Plugin)
For ecommerce store owners, it’s crucial to expand your business’s online reach and customer lead conversions and build a strong relationship with the audience. With Google Analytics and other analytics tools, marketers can only add so much value to the process, but it can be more effective by adding tags.
With the Enhanced Ecommerce extension by WeltPixel, you can measure data efficiently, which is crucial today. Let’s start installing and configuring the Google Tag Manager extension in Magento 2.
Features of Magento 2 Google Tag Manager
The Magento GTM extension can be downloaded from WeltPixel. When installed, it offers the following significant features to help you manage and improve your Magento ecommerce store.
- Track product clicks and impressions by their position in the category and search results pages. Moreover, the extension can also track upsell and cross-sell products.
- Track the number of times a product was added or removed from the shopping cart.
- Track the number of times a product was added to the wishlist or into the checkout process.
- Add multiple Child vs. Parent (Send Parent Id or Child Id cart, checkout, and thank you page) and track how often these products were compared.
- Follow the store’s checkout process (billing, shipping, shipping options, payment options), purchases with or without shipping and tax fees, and coupon usage.
- Ensure the store’s GDPR compliance with native Magento accepts cookie functionality.
Install Magento 2 Google Tag Manager Extension
Installing Magento 2 Google Tag Manager Extension follows the standard process of installing any other Magento extension:
- Step 1: Download the extension zip file from the official website.
- Step 2: Unzip Magento 2 Google Tag Manager to a folder on the desktop.
- Step 3: Transfer the WeltPixel folder to the app/code folder. The path will look like:
Copy the extension files into the below path of your Magento 2 instance. If the ‘app/code/WeSupply’ folder is missing, please create it manually: app/code/WeSupply/Toolbox.
- Step 4: Access the root folder of your Magento 2 project from the command line and run the following commands:
php bin/magento module:enable WeltPixel_Backend --clear-static-content
php bin/magento module:enable WeltPixel_GoogleTagManager --clear-static-content
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
- Step 5: Flush the caches on both server and Magento
php -d memory_limit=-1 bin/magento cache:flush
You have successfully installed the Magento Google Tag Manager extension at your ecommerce store. Now, let’s go through the process of changing the settings and configurations.
Before configuring the Magento 2 Google Tag Manager extension, create your account on Google Tag Manager.
Next, log in to the dashboard of your ecommerce store and follow the steps below.
- Go to WeltPixel → Enhanced ecommerce GTM Settings → Google Analytics Enhanced Ecommerce
Magento GTM Configuration
Step 1: Configure Google Analytics Magento 2
- Navigate to Admin → Store → Configuration → Sales → Google API → Google Analytics → and set this option to [No].
- Next, go to Admin → Store → Configuration → Sales → Google API → Google Adwords → and set this option to [No].
- Navigate to WeltPixel → Enhanced Ecommerce GTM Settings → Google Analytics Enhanced Ecommerce → General Configuration → Enable Google Tag Manager and set this option to Yes.
Step 2: Create Google Tag Manager Account
- Create a Google Tag Manager account if you don’t have one at this link: https://www.google.com/analytics/tag-manager/.
- Setup Account name, Setup Container, and Target Platform from your Google Tag Manager like
- Click Create Button to create an account and agree on the terms & conditions to YES.
Step 3: Setup Google Analytics In Magento 2
- Once the account is created, get the Google Tag Manager (GTM) scripts to configure in Magento 2 Backend.
Note: If you already have a Google Tag Manager (GTM) account, you can find the script in your Google Tag Manager account as
- Select the Admin section.
- From the right corner, Click on Install Google Tag Manager, and a preview will show the code, as seen in the screenshot.
- Now go to WeltPixel → Google Analytics Enhanced Ecommerce → General Configuration → Google Tag Manager Non-Js Code and paste the code for the “<body>” section in your magento store.
In the Impression, Chunks Size field, mention the size of chunks in which page impressions will be sent. Since this will directly impact the page load time and the overall performance of your ecommerce store, it is recommended that you keep it to 15 impressions per chunk for smooth performance.
- Through Product Identifier, you can choose how you want to identify the products in Google Analytics and Google Tag Manager. Your options include SKU or product ID
- If you want to have each product brand tracked in Google Analytics reports, Enable Brand to Yes and use the appropriate Brand Attribute.
- Through Order Success Page Total Calculation, you can either select Subtotal or Grand total
- If the Measure Product Clicks field is set to Yes, it will track product clicks on category pages.
- Select Promotion Tracking to Yes if you want to measure both impressions and clicks for internal site promotions
- In Persistent data layer expiry time, you can define data layer expiry time in minutes.
- The field Exclude Tax From Transaction allows you to exclude taxes from the transactions.
- The field Exclude Shipping From Transaction allows you to exclude shipping costs from transactions.
- Through the Child vs. Parent category, you can select either Parent id or Child id for the cart, checkout, and thank you page.
- The field Custom Dimension – Customer ID allows you to pass the Customer ID to GTM as Custom Dimension. You can also define Custom Dimension in your GA account.
- Custom Dimension – Customer Group: Allows you to pass the Customer Group to GTM as Custom Dimension. You have to define this Custom Dimension also in your GA account.
Next, before configuring Magento 2 Google Tag Manager API, you need to get your Account ID and Container ID from Google Tag Manager:
Magento GTM API Configuration
Step 1: Setup GTM API Configuration In Magento 2
- To create triggers automatically with one click by default, you need to set up Google Tag Manager (GTM) API Credentials to link your store with your GTM account automatically.
- For this, navigate to WeltPixel → Google Analytics Enhanced Ecommerce → GTM API Configuration and fill in your Account ID, Universal Analytics Tracking ID received from Google Analytics, and next Container ID you will receive from Google Tag Manager.
Step 2: Get Universal Analytics ID
If you don’t already have a Google Analytics Property, head to the Google Analytics website and create one.
- Click on Admin (Settings icon at the bottom left corner) and then Create New Account.
- Fill Account Name, choose the sharing settings, and proceed to the next step.
- Choose the Property Name, currency, and Timezone for your Google Analytics account.
- After this, you need to click on the Show Advanced Options button to be able to create a Universal Analytics Property.
- Turn on the Create a Universal Analytics Property toggle and input your website’s URL.
- Select Create a Universal Analytics Property only and hit Next.
- After this, fill up your About Business Information, select Industry Category, Business Size, and intend use.
- Next, click on the Create Button and click on the checkbox to accept the terms.
- You’ll automatically be taken to a Property section where you can see your Universal Analytics Tracking Code.
- Get the Tracking Id available under Admin → Property settings → Tracking ID.
Step 3: Link Google Tag Manager With Magento 2
In this section, to automatically link your store with your GTM account and create default provided triggers, you will need to configure Google Tag Manager (GTM) API Credentials.
- Log in to your Magento Admin
- Navigate to WeltPixel → Google Analytics Enhanced Ecommerce → GTM API Configuration.
- Now fill out filling Account ID, Container ID, and Universal Analytics Tracking ID.
- The field IP Anonymization allows website owners to request their users’ IP addresses.
- Now hit the Sign in to Google button and link your Google Tag Manager (GTM) account with your Magento Store.
You will be notified to save your credentials in order not to lose them before continuing with the process.
Hit the Save Config button.
JSON Expert Options
Alternatively, if the Sign in to Google functionality does not work, you can export the configuration as a JSON and import it into your Google Tag Manager container.
Step 1: Generating JSON
- Log in to the Magento 2 Admin
- Navigate to WeltPixel → Google Analytics Enhanced Ecommerce → JSON Export Options and click on the Generate Json for Variables, Triggers, and Tags button.
- Public ID will be the GTM container ID.
- You will be notified about the Variables, Triggers and Tags created. and a Download JSON button will appear. Click the button to download the generated JSON.
Step 2: Google Tag Manager (GTM) Admin
- Now Go to your Google Tag Manager Dashboard, select the Admin tab, and choose Import Container.
Step 3: Importing JSON
This step is to import the previously generated JSON to ensure Google picked the settings.
- Click on the Choose container file button to upload the previously generated and downloaded JSON file.
- Then, choose a workspace (you can choose an existing workspace or create a new one) and an import option.
Step 4: Preview And Confirm
- After JSON is imported, a preview will show up, letting you know the number of changes made to the container.
- Tags, Triggers, and Variables should be created or updated in various amounts depending on your Magento Admin settings.
- Click on Confirm, and you should be done with importing your settings!
Step 5: Publish / Submit Tags
- After all your tags have been created in Google Tag Manager (GTM), go to your Google Tag Manager (GTM) account and PUBLISH / SUBMIT all your tags by following the steps from Google Tag Manager.
- ! NOTE: No tracking will be available if the container is not published/submitted in your GTM account. Make sure to publish your container.
After clicking on Submit Button, fill in the Version name and description to publish the container with the version.
You can now view your version: tags, Triggers, and variables:
Step 6: Checkout Ecommerce Setup
In your Google Analytics account, navigate to Admin → Ecommerce Settings to define the labels for checkout steps.
Step 7: Integrate Google Analytics With Magento 2
To check the conversions rate growth through Google Analytics of your store, you need to set up:
- Enable Ecommerce.
- Enable Enhanced Ecommerce Reporting.
- Add Checkout Labeling (Funnel Steps): Identify the checkout steps of your ecommerce store using Google Tag Manager (GTM) before adding them for tracking.
- Save Ecommerce set-up
For more information, please check this: Set up Enhanced Ecommerce Reports.
Configure Google AdWords Conversion Tracking
You can get all the necessary IDs from your Google AdWords account by setting up the tag as shown below:
- Enable your Google Adwords conversion tracking to Yes.
- Google Conversion ID – You need a Google AdWords account, adwords.google.com. Follow Google documentation on how to find Google Conversion ID for AdWords.
- Google Conversion Label – Follow Google documentation on how to find Google Conversion Label for AdWords.
- In Conversion Currency Code, define the currency in which you would like to track your Adword Conversion.
Enable Google AdWords Remarketing
- Enable your Google AdWords Remarketing to Yes.
- Get your Conversion Code by following the google documentation for Google AdWords Remarketing.
- Get your Conversion Label – for this, follow the google documentation on how to find Google Conversion Label for Google AdWords Remarketing.
Link Google Analytics Account With Adwords
Tracking different conversions of google Ads would be a trivial task. Once you link Google Ads with Google Analytics, it’s much easier to see which keywords and ads generate conversions. Analytics can filter data at various levels by conversions.
When you link Google Ads and Analytics, it’s easier to check ads and site performance data in the Google Ads reports in Analytics.
Step 1: Google Ads Linking
- Go to your Google Analytics account Admin.
- Under the Product Links column, click on Google Ads Linking.
Step 3: Setup Configuration
- Select the Google Ads to the account you want to link.
- Once all link configuration is done, click on the Link accounts
- Google Analytics is now linked to AdWords successfully.
Set up GA Custom Dimensions & Metrics
Custom Dimensions and custom metrics are used to collect and analyze data that Google Analytics doesn’t automatically track. This extension allows you to track multiple custom dimensions specific to each custom dimension scope.
You must set up custom dimensions in Google Analytics to enable tracking. Follow the below steps to set up custom dimensions and custom metrics.
Step 1: Custom Dimension
- Go to your Google Analytics account Admin
- Navigate to the Property column, and click on Custom Definitions → Custom Dimensions.
Step 2: Create New Dimension
Starting with custom dimension scopes and indexes, the ones created in Google Analytics match with Magento.
- Click On +New Custom Dimension
Next, fill in the following fields:
- Insert Custom Dimension Name such as Customer ID.
- Select the Custom Dimension Scope as such as User for Customer relevant Dimension.
Note: If you are creating a product-relevant dimension, you need to choose Product scope.
- Make sure the Active box is checked.
- Click on the Create button.
Next, click on the Done button to complete the creation of Custom Dimension.
Repeat this step to create other dimensions, like Customer ID, Customer Group, Page Type, Stock Status, Reviews Count, Review Status, and Sale Product.
Step 3: Success
Trouble with GTM Setup? But don’t worry, preview you can easily debug and troubleshoot your GTM setup regardless of your expertise level Use GTM Preview functionality.
Go to your GTM account, and in the top right corner, you will see the Preview Button.
Magento 2 Google Tag Manager extension eliminates the need to configure multiple extensions by providing a single Magento GTM extension. As a result, you will significantly increase your productivity and discover that your overall tracking and store-level analytics analysis has been dramatically simplified – proof that this is a must-have extension for your Magento store.
Customer Review at
“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”
Stefan [Management Consultant]
Jyotishina is the Magento Community Expert at Cloudways and has 4 years of experience in web development. She has worked on e-commerce sites since the turn of the millennium and was working with Magento before version 1 was released. She loves to travel and explore new ideas whenever she finds time. Get in touch with her at [email protected]