analytics

Tracking data in Shopify is super easy, especially with the Shopify customer events setup. However, it's a bare minimum that gives you limited insights about the catalogue, cart and checkout behaviours. To track all of the important eCommerce events and optimise conversion tracking, you need Google Tag Manager (GTM). 

It allows you to manage all your tags, including Google Analytics 4 and Ads, from one place. This makes updates and customisation less troublesome.

So, in this guide, you'll learn how to set up Google Tag Manager in Shopify and test the implementation. All without touching your Shopify theme code more than once.

We'll also share how to create all the important tags and triggers automatically inside GTM.

Intrigued? Let's begin with the basics.

What is Google Tag Manager and Why You Need It?

If you're not running any advanced marketing campaigns or multi-tool tracking, the basic Shopify GA4 tool is probably enough.

However, if you want more accurate data, advanced e-commerce tracking (form submission, refund, scroll, etc), you have to set up GTM.

What is Google Tag Manager in Shopify?

Google Tag Manager (GTM) is a free tag management system that allows you to install, manage, and update marketing and analytics tags on your website — without modifying Shopify theme every time.

Instead of managing code snippets for Google Analytics 4 (GA4), Google Ads and Facebook Pixel inside a Shopify theme, you add only one GTM snippet. One time.

From there, you can edit, add or remove all the tags and triggers from your GTM dashboards. It's as simple as that.

new google tag manager account

Unlike a limited Google Analytics 4 setup in Shopify, GTM allows you to control when tags fire, pass dynamic product or customer values, and do a lot more. 

This leads to cleaner code, easier marketing workflow and compliance with different privacy regulations.

Google Tag Manager vs Google Analytics

While they’re often used together, Google Tag Manager and Google Analytics are not the same. They serve different purposes. It's important to understand that before you setup Google Tag Manager for Shopify. 

Google Analytics collects, measures and visualises data about how people use your website. It's a tool that tracks traffic sources, user behaviour, sales, etc.

Google Tag Manager, on the other hand, is a management system. It doesn't track anything on itself. It just lets you control all the tracking scripts (tags) in one place.

In other words, GTM is a hub for measurement tools, while Google Analytics is a tool that analyses the data collected by those tools.

How to Set Up Google Tag Manager in Shopify?

Adding Google Tag Manager to Shopify comes down to a few steps. All you need is to add the GTM script to your Shopify theme. But still, let's make sure you miss no steps.

Step 1: Create a Google Tag Manager account

If you haven't done it already, navigate to Google Tag Manager and set up a new account. 

Create Google Tag Manager Account

Then, specify the basic information like Account NameCountry and Container name. Choose Web as your Target Platform, and you're all set.

Google Tag Manager Configuration

Right after you agree to the terms and conditions, you'll see a pop-up with the two snippets of code you need to embed into your theme.

Step 2: Add GTM code to Shopify theme

If you accidentally close the pop-up or have already created the GTM account before, simply click on your GTM public ID (GTM-XXXXXX) or go to Admin > Install Google Tag Manager to find the code snippets.

install google tag manager

Then navigate to Sales channels > Online Store > Themes inside your Shopify admin and click on the three dots to find the Edit code option.

Once in the theme files, go to the theme.liquid file and paste the first (<head>) code snippet from your GTM account right under the meta tags.

install google tag manager in shopify

Then scroll down to the body tag and paste the second (<body>) code snippet under it. Don't forget to Save the changes and move to the next step.

add google tag manager code to shopify

Note: use the Crtl +F combination to find <meta> and <body> tags within the code since the location might be different, depending on your website.

Just make sure to paste both snippets as high as possible within the respective tags. It ensures the GTM script runs as fast as possible.

Step 3: Add GTM Code to Shopify "Thank you" page

Once you add the GTM script to your Shopify theme, Google Tag Manager is considered installed. However, unfortunately, it doesn't cover your entire website. It doesn't cover checkout or thank-you pages, in particular. 

In fact, only Shopify Plus users have access to the checkout.liquid file to track checkout events. But you can still track the purchase on the thank-you page.

For that, navigate to your Shopify admin > Settings > Checkout and find the Additional scripts field under the Post-purchase section. Paste both <head> and <body> GTM scripts there, one under the other. Then Save the settings, and that's it.

additional scripts post purchase page shopify

Step 4: Test the installation

Finally, you have to check if Google Tag Manager is working, once you add those scripts. Just go back to your GTM Workspace and hit Preview.

preview gtm tags

You'll enter the Tag Assistant, which asks you to paste your website URL for debugging. Then click Connect.

tag manager assistance

Note: if your store is password-protected, the Preview might not work. Try lifting the password for testing or reconnect to the Tag Assistant again.

Your website will open in a new window with the Tag Assistant pop-up. If you see the Tag Assistant Connected message, then you've installed Google Tag Manager in Shopify correctly.

tag assistant connected shopify

Back in the Tag Assistant tab, you should see the GTM script fired every time you switch to a new page on your store.

debugging google tag manager

Note: if you've already set up GTM tags, you should see them fired in this tab. However, if you've just installed GTM in Shopify, it's fine if you see no tags. The main thing is that you've connected Google Tag Manager to your store.

Alternatively, you can use the browser dev tools to make sure the GTM script fires properly directly in your code.

gtm in browser dev tools

After you do the testing and confirm that you've set up Shopify Google Tag Manager properly, just hit Submit in the GTM workspace. Name the first version (if it is actually the first one) something like "Initial setup", and start creating your tags.

Set up Tags, Triggers and Variables

Connecting GTM to Shopify is not that hard. The real challenge is making the right tags fire at the right time and pass the right information about your store. 

It might seem like too much. But we'll break down the basics and show you how to set them up automatically.

The basics of GTM tags, triggers, and variables

The GTM does all the heavy lifting with firing and tracking valuable data about your store's performance. However, it should still know what and when to track.

Tags (what you want to fire) — are basically snippets of code that send data to third-party tools. These tags might be:

  • Google Analytics 4 tag — for collecting data about users' behaviour and sending it to GA4.

  • Google Ads Conversion Tracking tag — for measuring ROI from your ad campaigns.

  • Facebook Pixel tag — for optimising Facebook ad campaigns.

  • Pinterest, TikTok, LinkedIn Tags tag — for optimising other ad campaigns.

ga4 tag in google tag manager

GA4 tag in Google Tag Manager

Pro tip: it's best to connect GA4 to Shopify via GTM (through tags) rather than Shopify events since you get more control over page views and events using triggers.

Triggers (when you want the tag to fire) — define conditions under which you want certain tags to fire. Some examples include:

  • Page view —  fired as soon as a customer visits a certain page.
  • Add to cart — fired when someone clicks the “Add to Cart” button.
  • File download — fired when someone downloads a free file from your store.
add to cart trigger gtm

GTM trigger for the "Add to Cart"

Variables (what data you want to pass to the third-party data processors) — provide dynamic information about pages, products and customers. There might be:

  • Built-in GTM variables —  page URL and path, referrer, etc.
  • Data layer variables — like product ID, revenue, transaction ID, etc.
  • Custom JavaScript or DOM variables
data variable gtm

Example of the transaction ID variable in GTM

What is a data layer?

Once you add the GTM scripts to your theme.liquid file and create all those tags and triggers, you still won't get any data in GA4, Google Ads or other tracking tools. Why? 

Because GTM doesn't have any context about what's happening on your store. Unless you tell it about it through the data layer. 

Data layer is a JavaScript with structured data about your products, cart actions, etc. That's where GTM takes information about when the add to cart, purchase or begin checkout happens.

Unfortunately, Shopify doesn't offer an eCommerce data layer by default. So, you need to implement it manually into your theme with a developer or a custom app.

Set up GTM Tags and Data Layer Automatically

Setting up the data layer is a final step in the Google Tag Manager setup for Shopify. That's also a step when things get confusing, especially for non-techies. But we've got a solution — Magefan Server GTM for Shopify

It's a tool that generates all the tags, triggers and variables for you within your GTM. You don't have to do anything, but insert a few tracking IDs from your GTM, GA4 and Google Ads accounts. That's literally it.

set up gtm server container for shopify

GTM setup through Magefan GTM App

The best part is Magefan GTM app helps you set up server-side tracking in Shopify. This allows you to avoid adblockers and cookie restrictions. You can now track all eCommerce events without losing valuable data. 

gtm triggers

All essential eCommerce events set up automatically with Magefan GTM

Important: if you decide to use Magefan GTM app, make sure to remove all the GTM tracking scripts from your theme.liquid file to avoid event duplication.

As we've mentioned before, Tag Manager and Google Analytics are two completely different tools helping you with your store analytics.

While the Shopify Google Analytics setup is good at the beginning, GTM definitely wins in the long run. 

It helps you to scale your data tracking, simplifying the management in the process. With the right set-up and implementation, you can collect better data and make smarter marketing decisions.

FAQs

Where do I put the Google Tag Manager code in Shopify?
collapsible icon
Navigate to Shopify admin > Sales channels > Online Store > Themes , start editing your theme and paste the and GTM scripts in the corresponding sections of the theme.liquid file.
Is Google Tag Manager better than adding tags manually in Shopify?
collapsible icon
Yes, definitely. Adding the GTM script once allows you to do all the customisation and editing within Google Tag Manager, rather than making changes to your Shopify theme every time.
Do I need a GTM app for Shopify or can I do it manually?
collapsible icon
You can set up Google Tag Manager in Shopify manually by inserting the GTM scripts into your theme.liquid file. But you also need to create all the tags and triggers inside GTM and implement the data layer to push events from Shopify to GTM. Using the app makes things easier.
Does GTM slow down my Shopify store?
collapsible icon
Loading GTM scripts in your Shopify influences the page loads, just like any other script. However, if you set up server-side tracking in Shopify through a GTM container, it decreases the influence on the loading speed.
Can I use server-side GTM with Shopify?
collapsible icon
Yes. But since the server GTM is harder to set up, it's best to use the third-party app for easier integration.