How to set up GTM (Google Tag Manager) in Magento 2 store

How to set up GTM (Google Tag Manager) in Magento 2 store
10 min read
28 September 2023

Do you find managing tags on your Magento 2 store to be a tedious task? Are you in search of a more efficient solution to handle these intricate pieces of code? If so, Google Tag Manager for Magento 2 offers the perfect solution.

Managing tags can be a complex and time-consuming endeavor, particularly if you lack technical expertise. Google Tag Manager (GTM) streamlines this process for store owners by allowing them to oversee and implement tracking codes on their websites without having to edit the site’s code. This simplifies tasks such as adding and removing tags, testing configurations, and monitoring website statistics, all without causing any slowdowns or disruptions to your site.

Let us guide you through the process of setting up GTM in Magento 2, using the simplest and most straightforward method that anyone can follow.

Google Tag Manager (GTM) is a user-friendly tool that simplifies tag management. Through GTM, stores can easily add, edit, or disable tags using a web-based interface, consolidating everything in one location without the need to manipulate the source code. This simplifies error identification and resolution.

Furthermore, the Google Tag Manager extension facilitates the monitoring of customer behaviors by linking web pages with Google Adwords, Google Analytics, and Facebook Pixel.

Google Tag Manager and Google Analytics are frequently mentioned together, leading to a common misconception that they are the same. However, these are distinct concepts.

Google Tag Manager is designed to collect data on user activities on a website, while Google Analytics is used to analyze the data collected. GTM gathers information and forwards it to Google Analytics for in-depth analysis, resulting in reports on conversions, engagement metrics, sales analysis, and more.

Benefits of Google Tag Manager: Google Tag Manager serves as the initial step in harnessing user behavior data, allowing store owners to formulate more tailored strategies. This extension is particularly invaluable for those who lack coding expertise, enabling them to efficiently oversee tags and reap significant advantages as outlined below:

  1. Streamlined Tracking of Website Events: GTM simplifies the monitoring of various user interactions, such as clicks, page views, and form submissions. This data provides insights into user engagement with your website, identifying areas for enhancement.

  2. Centralized Tracking Code Management: The extension consolidates all tracking codes into a single location, saving time, reducing effort, and minimizing the risk of errors.

  3. Expedited Tag Deployment: This tool facilitates the swift implementation of new tracking codes, eliminating the need to wait for website updates.

  4. Enhanced Website Speed: GTM loads tracking codes asynchronously, ensuring they do not impede your website’s loading speed.

  5. Enhanced Data Precision: The module enhances data accuracy by offering a more efficient tag management solution.

Why Google Tag Manager Is Essential for Your Magento Store: In addition to the benefits mentioned above, there's another compelling reason why the Google Tag Manager extension is essential for your store.

Medium-sized or larger online businesses often need to update tags regularly with substantial amounts of data, whether on a weekly or monthly basis. Stores without GTM may encounter website disruptions as it takes considerable time to identify errors scattered across numerous source codes. In contrast, the GTM module simplifies error management by consolidating everything in one location, allowing for quick identification and resolution.

Furthermore, integrating a feature-rich module like the Mageplaza Google Tag Manager extension for Magento 2 streamlines activities in conjunction with Google Analytics and AdWords, opening up numerous possibilities for efficient monitoring of store statistics and easy adjustment of marketing tags and code snippets.

Google Tag Manager Hierarchy: While Google Tag Manager may take some time to become familiar with, it provides a user-friendly experience overall. The initial steps with GTM may appear intricate as you need to acquaint yourself with new terminology and adapt to its operational structure.

The GTM hierarchy is organized as follows: GTM Account > Container > Tracking Tag > Tag Triggers.

  1. GTM Account: Each Gmail address can have multiple GTM accounts, but one account is sufficient if you only need to manage your website.

  2. Container: Within the GTM account, you create a container, an entity that houses all tracking tags associated with a specific data source. Containers can be configured for various target platforms, such as web pages, iOS apps, Android apps, AMP pages, or server-side applications. While one container corresponds to one platform, you can include multiple containers within each account. In this blog post, we focus on web page containers. To install the container onto your website, insert specialized code snippets into your site’s HTML structure, placing one code set within the head section and the other after the opening body tag.

  3. Tags: After integrating GTM code snippets into your site’s frontend, you can configure tracking tags within the GTM interface. A tracking tag is a piece of code designed to transmit data when a predefined event occurs, such as a customer clicking a button. Tags collect data using variables, and GTM provides 44 built-in variables for websites. Additionally, website owners can define custom variables using JavaScript and CSS, enabling tracking of nearly any action on their site. GTM offers a library of predefined tag templates, or you can create your own templates.

  4. Triggers: Tracking tags rely on triggers for activation. Triggers are conditions that determine when a tag should execute, such as when a user clicks a button. Google Tag Manager provides various trigger categories, including page view triggers, click triggers for element or link clicks, user interaction triggers for events like video views and form submissions, and an array of other triggers, including those for tracking JavaScript errors.

  5. Variables: Variables are additional pieces of information that GTM may require for a tag or trigger to function. They precisely specify what actions the tag or trigger should take.

  6. Workspaces: GTM supports multiple workspaces, enabling team members to collaborate concurrently without overwriting each other’s work.

  7. Versions: Every time you publish changes, GTM generates and records a new code version. This feature allows you to review past and current modifications and revert to previous versions if necessary.

How to Set Up GTM in Magento 2: Setting up GTM in your Magento 2 store is a straightforward process. Here's a step-by-step guide:

Step 1: Visit the Google Tag Manager website "https://tagmanager.google.com/"

Step 2: Sign up for a Google Account

  • Click "Create Account" in the top right corner and fill in the required information.

Step 3: Enter all the necessary information

  • Set the account container by naming it and choosing the target platform (select "Web" for website data gathering).

Note: To delete a container, go to Admin -> Container Settings -> More menu (represented by three vertical dots) -> Settings -> Delete. You have 30 days to change your mind and restore the container before Google permanently deletes it.

Step 4: Add the Google Tag Manager code to your website

  • After setting up the account, click "Create" to create a new container, and a pop-up window will display Google's terms of use. Select "Yes" to agree to Google's conditions.

  • A table containing the container's codes will appear.

  • In this section, you'll find two sets of code: "Head" and "Body." Copy and paste these code sets into every page of your website. Place the first code set within the head section of your page and insert the second code set right after the opening body tag. Then, click "OK" to close the table.

Step 5: Get the Container ID and insert it into your Magento store

  • After closing the table, you should return to the Workspace page. Click "Admin" on the section bar, and the page will reload, displaying the container ID next to it.

  • Insert this Container ID into your Magento store by going to "Stores" > "Configuration" > "Mageplaza Extensions" > "Google Tag Manager."

  • In the "Enable" field, select "Yes."

  • In the "Google Tag ID" field, paste the Container ID you obtained on the Admin page. Be sure to click "Save Config."

How to Create New GTM Tags: Creating new tags in Google Tag Manager is a straightforward process. Here's how to do it:

Step 1: Click on "New Tag" in the left sidebar.

Step 2: Set up the tag with the necessary information:

  • Tag Configuration: Choose the tag type and configure it accordingly.

  • Triggering: Select a trigger to determine when the tag should fire.

  • Save the tag.

Note: When using Google Tag Manager to manage Google Analytics, avoid duplicating your data. Remove the existing Google Analytics tracking code from your pages to prevent collecting duplicate data.

In conclusion, Google Tag Manager offers a user-friendly solution for managing tags on your Magento 2 store. It simplifies the process of tag management, allowing store owners to efficiently oversee and implement tracking codes without the need to edit the site's code. By integrating Google Tag Manager with other modules such as Google Analytics and AdWords, you can make data-driven decisions and optimize your store's performance.

Discover the benefits of Google Tag Manager and streamline your tag management process today!"

In case you have found a mistake in the text, please send a message to the author by selecting the mistake and pressing Ctrl-Enter.
Vinh Jacker 12
CTO of Mageplaza. Have big love and passion for technology. A professional coder and an ultra-marathon runner. With a decade of extensive experience, I am an ex...
Comments (0)

    No comments yet

You must be logged in to comment.

Sign In / Sign Up