How To Use Google Tag Manager For Magento 2

a person sitting at a table with a laptop

Google Tag Manager (GTM) is a free tool provided by Google that makes it easy for you to add and update measurement codes across your website or mobile app. The tool is extremely useful for marketers and developers who need to add tracking code to Magento 2. GTM lets you have full control over your website’s tracking pixel and code management.

Speed Up Your Magento Store by 300%

In this article, we will show you how to use Google Tag Manager for Magento 2.

Step 1: Create a GTM Account

The first step is to create a Google Tag Manager account. You can create an account by visiting the Google Tag Manager website and signing up. Once you have signed up, you will be redirected to the GTM dashboard.

Step 2: Create a Container

A container is a place where all your tracking codes will reside. After you have created an account, the next step is to create a container. To create a container, click on the “Create Container” button on the GTM dashboard.

You will be prompted to provide a container name. You can choose whatever name you like, but we suggest using something that is relevant to your website or business.

Step 3: Add GTM Script to Magento 2

After you have created a container, the next step is to add the GTM script to your Magento 2 website.

First, you need to copy the GTM code that Google will provide you with. Go to the “Install Google Tag Manager” page and copy the “GTM-XXXXXXX” code for the container you just created.

Next, you need to go to your Magento 2 backend and navigate to the "Content" > "Configuration" section. Select the “Edit” option for the theme you are using and scroll down to the “HTML Head” section.

In the “Scripts and Stylesheets” text area, paste the GTM code. Make sure to save the changes.

Step 4: Create a Tag

The next step is to create a tag. A tag is a specific piece of code that you want to track on your website. For example, if you want to track the number of visitors to your website, you need to create a tag for that.

To create a tag, go to the GTM dashboard and select the container you created earlier. Click on the “New Tag” button to create a new tag.

You will be prompted to provide a name for the tag. Choose a name that is relevant to the code you want to track.

Next, select the tag type. The tag type will depend on the tracking you want to do. For example, if you want to track page views, select “Universal Analytics” as your tag type.

Step 5: Set Up Trigger

After you have created a tag, the next step is to set up a trigger. A trigger is what activates the tag and tells it to track an event.

To create a trigger, click on “Triggering” in the tag configuration area.

Select the type of trigger you want to use. Common triggers include “All Pages” which tracks events on all pages of your website and “Pageviews” which tracks specific page views.

Step 6: Publish Changes

After you have created the tag and trigger, you need to publish the changes. To do this, click on “Submit” at the top of the GTM dashboard.

You will be prompted to provide a version name and description. Add a name and a description, then click “Publish”. Your changes will now be live on your website.

Conclusion

Google Tag Manager is a powerful tool that can help you track and measure website events and activities. By following the steps outlined in this article, you can easily add GTM to your Magento 2 website and start tracking events today! Remember to update your tags and triggers as your business evolves and new tracking needs emerge.

Scroll to Top