Skip to main content
wpcrux.com

Back to all posts

How to Set Up Google Tag Manager For Magento 2?

Published on
7 min read
How to Set Up Google Tag Manager For Magento 2? image

Best Tools for Google Tag Manager to Buy in September 2025

1 Manager 1 x 3 Name Tag, Brushed Gold (3 Pack)

Manager 1 x 3 Name Tag, Brushed Gold (3 Pack)

  • EYE-CATCHING BRUSHED GOLD WITH BOLD BLACK TEXT FOR VISIBILITY
  • DURABLE ENGRAVING FOR A PROFESSIONAL LOOK THAT LASTS
  • EASY PIN FASTENER FOR QUICK AND SECURE ATTACHMENT
BUY & SAVE
$9.99
Manager 1 x 3 Name Tag, Brushed Gold (3 Pack)
2 Store Manager 1 x 3 Name Tag/Badge, Red, (3 Pack)

Store Manager 1 x 3 Name Tag/Badge, Red, (3 Pack)

  • EYE-CATCHING RED WITH WHITE TEXT FOR INSTANT RECOGNITION
  • INCLUDES PIN FASTENER FOR EASY ATTACHMENT AND USE
  • PERFECT FOR STORE MANAGERS & RETAIL STAFF TO ENHANCE PROFESSIONALISM
BUY & SAVE
$9.99
Store Manager 1 x 3 Name Tag/Badge, Red, (3 Pack)
3 PDX CNC Edgeview CNC Tool Holder Tool Tag - 25-pk Label Organizers (CAT40/HSK63A)

PDX CNC Edgeview CNC Tool Holder Tool Tag - 25-pk Label Organizers (CAT40/HSK63A)

  • QUICK-GLANCE DESIGN FOR FAST IDENTIFICATION IN ANY SHOP.
  • DURABLE, USA-MADE PETG MATERIAL WITHSTANDS TOUGH ENVIRONMENTS.
  • EASY INSTALLATION SAVES TIME AND REDUCES CONFUSION FOR USERS.
BUY & SAVE
$29.99
PDX CNC Edgeview CNC Tool Holder Tool Tag - 25-pk Label Organizers (CAT40/HSK63A)
4 MINYULUA Sheep Ear Tag Plier Kit 300pc 1-100 Number Plastic Livestock Ear Tag with Ear Tags Tool and Animal Tagging Plier Marker Applicator for Goat Dog Cattle

MINYULUA Sheep Ear Tag Plier Kit 300pc 1-100 Number Plastic Livestock Ear Tag with Ear Tags Tool and Animal Tagging Plier Marker Applicator for Goat Dog Cattle

  • SAVE TIME AND LABOR WITH EASY LIVESTOCK MANAGEMENT AND TAGGING.
  • DURABLE LASER-PRINTED TAGS IN VIBRANT COLORS FOR CLEAR IDENTIFICATION.
  • COMPLETE KIT INCLUDES APPLICATOR AND PLIERS FOR HASSLE-FREE TAGGING.
BUY & SAVE
$33.98 $37.98
Save 11%
MINYULUA Sheep Ear Tag Plier Kit 300pc 1-100 Number Plastic Livestock Ear Tag with Ear Tags Tool and Animal Tagging Plier Marker Applicator for Goat Dog Cattle
5 Practical Google Analytics and Google Tag Manager for Developers

Practical Google Analytics and Google Tag Manager for Developers

BUY & SAVE
$64.13 $79.99
Save 20%
Practical Google Analytics and Google Tag Manager for Developers
6 Portable Key Organizer,Zippered Key Organizers Case with 48 Key Hooks and Tags Key Storage,Leather Apartment Manager and Landlord Key Holder,Key Organizer Box for Real Estate Sales,Hotels,Car Service

Portable Key Organizer,Zippered Key Organizers Case with 48 Key Hooks and Tags Key Storage,Leather Apartment Manager and Landlord Key Holder,Key Organizer Box for Real Estate Sales,Hotels,Car Service

  • ORGANIZE UP TO 48 KEYS WITH VIBRANT TAGS FOR EASY IDENTIFICATION!
  • DURABLE ZINC ALLOY HOOKS ROTATE 360° FOR EFFORTLESS ACCESS AND STORAGE.
  • HIGH-QUALITY LEATHER DESIGN FOR A PREMIUM LOOK AND LASTING DURABILITY.
BUY & SAVE
$35.66
Portable Key Organizer,Zippered Key Organizers Case with 48 Key Hooks and Tags Key Storage,Leather Apartment Manager and Landlord Key Holder,Key Organizer Box for Real Estate Sales,Hotels,Car Service
7 Secure ID Utility Shut-Off Tags – Set of 3 PVC Valve Labels for Gas, Water & Hot Water – Landlord & Property Manager Safety Tags for Rentals or Multi-Unit Homes

Secure ID Utility Shut-Off Tags – Set of 3 PVC Valve Labels for Gas, Water & Hot Water – Landlord & Property Manager Safety Tags for Rentals or Multi-Unit Homes

  • INSTANT IDENTIFICATION: QUICKLY LOCATE SHUT-OFF VALVES IN EMERGENCIES.
  • DURABLE DESIGN: WATERPROOF PVC TAGS ENSURE LONG-LASTING VISIBILITY.
  • COLOR-CODED CLARITY: INDUSTRY-STANDARD COLORS MINIMIZE CONFUSION.
BUY & SAVE
$15.95
Secure ID Utility Shut-Off Tags – Set of 3 PVC Valve Labels for Gas, Water & Hot Water – Landlord & Property Manager Safety Tags for Rentals or Multi-Unit Homes
+
ONE MORE?

To set up Google Tag Manager for Magento 2, you need to follow these steps:

  1. Create a Google Tag Manager account: Go to the Google Tag Manager website and sign in with your Google account or create a new one if you don't have one.
  2. Set up a new container: Once you're logged in, click on "Create Account" and provide the necessary account name and container name for your Magento 2 website.
  3. Get the container code: After creating the container, Google Tag Manager provides you with a container code snippet. Copy this code as you'll need to add it to your Magento 2 website.
  4. Access your Magento 2 admin panel: Log in to your Magento 2 admin panel using your credentials.
  5. Install the Google Tag Manager extension: In your Magento 2 admin panel, go to System → Web Setup Wizard → Component Manager. Search for the Google Tag Manager extension and click on "Install."
  6. Configure the extension: Once the installation is complete, go to Stores → Configuration → Sales → Google API. Here, you can paste the container code you copied earlier in the "Google Tag Manager ID" field.
  7. Save the changes: Click on "Save Config" to save the updated Google Tag Manager configuration.
  8. Clear cache: Finally, go to System → Cache Management and clear the cache to ensure that the changes take effect.

Now you have successfully set up Google Tag Manager for your Magento 2 website. You can proceed with adding tags, triggers, and variables in the Google Tag Manager interface to track various events and actions on your website.

To track outbound link clicks using Google Tag Manager in Magento 2, follow these steps:

  1. Create a Google Analytics Tag in Google Tag Manager: Log in to your Google Tag Manager account. Select your container and navigate to "Tags" in the left sidebar. Click on "New" to create a new tag. Name the tag and click on "Tag Configuration". Choose "Google Analytics - Universal Analytics" as the tag type. Configure the tag with your Google Analytics tracking ID. Enable "Enable overriding settings in this tag" and select "Fields to Set". Add a new field with the following values: Field Name: "transport" Value: "beacon" Save the tag.
  2. Set up a trigger to fire the tag: Click on "Triggering" in the tag configuration. Click on "Choose a trigger to make this tag fire" and select "All Pages" trigger. Save the trigger and the tag.
  3. Enable Click Listener Variable in Google Tag Manager: Go to "Variables" in the left sidebar. Click on "Configure" under Built-In Variables. Enable the "Click URL" variable. Save the changes.
  4. Update the Magento 2 template files: Access your Magento 2 instance and go to your theme's directory. Edit the /Magento_Theme/templates/html/link.phtml file. Find the line that starts with , usually around line 20. Add the following line of code after the line mentioned above: getOutboundUrl($block->escapeUrl($block->getHref())); ?> Replace the existing line with the following one: href="" onclick="dataLayer.push({'event': 'outboundLink','outboundUrl': ''});"> Save the changes.
  5. Add a Custom JavaScript Variable to Google Tag Manager: Go to "Variables" in the left sidebar. Click on "New" to create a new variable. Name the variable as "gtm.linkClickOutbound". Choose the Variable Type as "Custom JavaScript". Paste the following JavaScript code into the "Variable Configuration" field: function() { return function() { return '{{Click URL}}'; }; } Save the variable.
  6. Create a Trigger to track outbound link clicks: Go to "Triggers" in the left sidebar. Click on "New" to create a new trigger. Name the trigger as "Outbound Link Click". Choose "Just Links" as the trigger type. Enable "Click URL" and set the condition to "matches CSS selector" and add a in the text box. Save the trigger.
  7. Update the Google Analytics Tag in Google Tag Manager: Go back to "Tags" in the left sidebar. Edit the existing Google Analytics tag. Add the trigger "Outbound Link Click" to the tag under "Triggering". Save the changes.

Once these steps are completed, Google Analytics will start tracking outbound link clicks on your Magento 2 website using Google Tag Manager.

What is the purpose of container versions in Google Tag Manager for Magento 2?

The purpose of container versions in Google Tag Manager for Magento 2 is to track and manage the changes made to the container. Containers are used to hold the various tags, triggers, and variables that are used to manage tracking and analytics within a website.

When a container is edited or updated in Google Tag Manager, a new version is created. These versions allow you to track, review, and revert changes made to the container. It ensures that you have a record of all the changes made, and you can easily go back to a previous version if needed.

Container versions also help in testing and debugging by allowing you to compare different versions and see the impact of changes on your website. It provides accountability and better control over the tracking and analytics implementations, ensuring that changes are properly documented and managed.

What is meant by data variables in Google Tag Manager for Magento 2?

In Google Tag Manager for Magento 2, data variables refer to the pieces of information that are used to collect and send data to various tags, such as Google Analytics, Facebook Pixel, or other marketing tools. These variables can be created and configured within Google Tag Manager to dynamically capture data from the Magento 2 platform.

Data variables can include information like the product ID, product name, category, price, transaction ID, customer ID, or any other relevant data points needed for tracking and analytics purposes. These variables can be utilized to customize the tracking and tagging implementation in Magento 2, allowing marketers and analysts to gather specific data about user interactions, conversions, and other metrics.

The recommended method for adding Google Tag Manager to a Magento 2 theme is as follows:

  1. Log in to your Magento 2 admin panel.
  2. Go to "Stores" and click on "Configuration."
  3. In the left sidebar, under "Sales," select "Google API."
  4. Expand the "Google Analytics" section and set "Enable" to "Yes."
  5. In the "Enable Content Experiments" drop-down, select "No."
  6. Under "Set up your Google Analytics," enter your "Account Number" and "Container ID" for Google Tag Manager.
  7. Save the configuration.

Now, you need to add the Google Tag Manager script to your theme files:

  1. Connect via FTP or SSH to your Magento 2 server.
  2. Navigate to your theme's directory, typically located at app/design/frontend/{Vendor}/{Theme}/Magento_Theme.
  3. Create a new folder called "layout" if it doesn't already exist.
  4. Inside the "layout" folder, create a new XML file, for example, "default.xml." This file determines where the script will be inserted into your theme.
  5. Open the XML file and add the following code:

Replace "YOUR_CONTAINER_ID" with your actual Google Tag Manager container ID.

  1. Save the XML file and clear Magento's cache.

By following these steps, you will have successfully added Google Tag Manager to your Magento 2 theme.