How to set up Google Tag Manager for Shopify

Author:

Setting up Google Tag Manager (GTM) for Shopify allows you to efficiently manage and deploy marketing tags, such as Google Analytics, Google Ads, Facebook Pixel, and more, without the need to modify the Shopify theme directly. This guide will walk you through the process of integrating Google Tag Manager with your Shopify store.

Step 1: Create a Google Tag Manager Account

If you don’t already have a Google Tag Manager account, follow these steps to create one:

  1. Sign up for Google Tag Manager:
  2. Create a New Container:
    • After logging in, click Create Account.
    • Enter your Account Name, Container Name, and select Web as the platform.
    • Click Create and accept the terms and conditions.
  3. Copy the GTM Container Snippet:
    • After creating the container, GTM will provide you with two snippets of code (one for the <head> and one for the <body> sections of your website). You will need these for the next steps.

Step 2: Add Google Tag Manager Code to Shopify

Now that you’ve set up GTM, you need to install the GTM container code on your Shopify store.

  1. Log into Shopify:
    • Go to your Shopify store and log into your admin panel.
  2. Navigate to the Theme Code Editor:
    • From the Shopify admin panel, click Online Store > Themes.
    • Find the theme you’re using and click Actions > Edit Code.
  3. Add the GTM Snippets:
    • Insert the first snippet in the <head>:
      • In the Layout folder, locate the theme.liquid file.
      • Paste the first GTM snippet (provided during GTM setup) inside the <head> section, just before the closing </head> tag.
    • Insert the second snippet in the <body>:
      • In the same theme.liquid file, paste the second GTM snippet immediately after the opening <body> tag.
  4. Save the Changes:
    • After adding the snippets to the appropriate places, click Save.

Step 3: Set Up Tags in Google Tag Manager

Once GTM is installed on your Shopify store, you can add various tags to track different activities, like pageviews, purchases, or add-to-cart events. Below are some common tags you might want to set up for Shopify.

1. Set Up Google Analytics (GA4)

Google Analytics is one of the most important tags for tracking user behavior.

  1. Create a New Tag for Google Analytics:
    • In Google Tag Manager, go to Tags and click New.
    • Click Tag Configuration and choose Google Analytics: GA4 Configuration.
  2. Enter Your Measurement ID:
    • You can find your Measurement ID in your GA4 property settings in Google Analytics.
    • Paste the Measurement ID into the tag configuration.
  3. Set the Trigger:
    • For Google Analytics, you’ll generally want to track Page Views. Select the All Pages trigger to fire on every page.
  4. Save and Publish:
    • Click Save to finish the setup.
    • Once you’ve configured and tested the tag, click Submit and Publish in GTM to make it live on your Shopify store.

2. Set Up Google Ads Conversion Tracking

To track conversions from your Google Ads campaigns, you’ll need to set up the Google Ads Conversion Tracking tag in GTM.

  1. Create a New Tag for Google Ads:
    • In GTM, go to Tags > New and select Tag Configuration.
    • Choose Google Ads Conversion Tracking.
  2. Enter Your Google Ads Conversion ID and Label:
    • In your Google Ads account, go to Tools & Settings > Measurement > Conversions to find the Conversion ID and Label.
    • Paste the Conversion ID and Label into the GTM tag configuration.
  3. Set the Trigger:
    • Choose the appropriate trigger to fire the tag. For example, if you want to track purchases, set the trigger to fire on the Thank You page or the page that confirms a successful order.
    • You can use a Page URL trigger to track conversions when the URL of the Thank You page matches the order confirmation page.
  4. Save and Publish:
    • After setting up the tag and trigger, click Save and then Submit to publish the changes.

3. Set Up Facebook Pixel

To track users’ interactions with your Shopify store via Facebook ads, you’ll need to set up the Facebook Pixel tag.

  1. Create a New Tag for Facebook Pixel:
    • In GTM, go to Tags > New, click Tag Configuration, and choose Custom HTML.
    • Paste the Facebook Pixel base code (you can find this code in your Facebook Ads Manager under Pixels).
  2. Enter Your Facebook Pixel ID:
    • Replace the default Pixel ID in the code with your unique Facebook Pixel ID.
  3. Set the Trigger:
    • Select All Pages if you want to track page views, or create a custom trigger for specific events (like purchases or add-to-cart).
  4. Save and Publish:
    • Click Save, then Submit to apply the changes.

Step 4: Set Up E-commerce Tracking in Google Tag Manager (Optional)

Shopify stores can track e-commerce events such as purchases, add-to-cart actions, and product views. This can be done using Google Analytics Enhanced E-commerce.

  1. Enable Enhanced E-commerce in Google Analytics:
    • In Google Analytics, go to your Admin section, under View, select Ecommerce Settings, and turn on Enhanced E-commerce.
  2. Set Up Enhanced E-commerce Tags in GTM:
    • In GTM, create a new tag for Google Analytics (GA4 or Universal Analytics).
    • Under Tag Configuration, enable Enhanced E-commerce.
    • Use the Data Layer to push events like product view, add-to-cart, checkout, and purchase to GTM. Shopify provides some basic data in the data layer, but you may need to customize it for more advanced tracking.

Step 5: Test Your Tags and Triggers

Before going live with your tags, it’s crucial to test them to ensure they work as expected.

  1. Use GTM Preview Mode:
    • In Google Tag Manager, click Preview in the top-right corner.
    • Enter your Shopify store’s URL and click Start.
    • GTM will open your store in a new tab with a debug console that shows which tags are firing.
  2. Verify Tags with Tag Assistant:
    • Use the Tag Assistant Chrome extension to check if the tags are firing correctly on your site.

Step 6: Publish Your Changes

Once you’ve verified that your tags are firing correctly:

  1. Publish Your Container:
    • In Google Tag Manager, click Submit in the upper-right corner.
    • Add a version name and description (e.g., “Shopify GTM Setup”) and click Publish.

Step 7: Monitor Performance and Data

After your GTM setup is live on Shopify:

  1. Monitor Google Analytics:
    • Check your Google Analytics account to ensure that data is being tracked (e.g., page views, events).
  2. Monitor Conversions:
    • Verify that Google Ads and Facebook Pixel are tracking conversions properly.

By following these steps, you’ll be able to manage all your tags from a central place (Google Tag Manager) and track important metrics across your Shopify store, enhancing your ability to make data-driven decisions for marketing campaigns and website performance.