Essential Shopify tracking guide with Google Tag Manager

Last updated:

Home » Articles » Shopify » Essential Shopify tracking guide with Google Tag Manager

What you’ll learn in this guide

This guide will show you how to track three essential customer interactions in your Shopify store using Google Tag Manager (GTM)

  • Page views: When customers browse different pages
  • Product views: When customers look at specific products
  • Collection views: When customers explore product collections

How to set up specific tracking

Step 1: Initial GTM setup in Shopify

  1. Log into your Google Tag Manager account
  2. Select your store’s account
  3. Go to Admin section
  4. Click ‘Install Google Tag Manager’
  5. Get your unique GTM code
  6. Remove the HTML tags from this code
  7. In Shopify admin, go to Settings > Customer Events > Custom Pixel
  8. Paste the modified code

Step 2: Setting up specific tracking

For page view

  1. In GTM workspace, click ‘New Tag’
  2. Choose ‘Google Analytics: GA4 Event’
  3. Set Event Name to ‘page_view’
  4. Add this code to your Shopify custom pixel:
analytics.subscribe('page_viewed', (event) => {
    window.dataLayer.push({
        'event': 'page_viewed',
        'page_location': event.context.window.location.href,
        'page_title': event.context.document.title,
    });
});

For product view

  1. Create another GA4 tag
  2. Set Event Name to ‘view_item’
  3. Add this code:
analytics.subscribe('product_viewed', (event) => {
    window.dataLayer.push({
        'event': 'product_viewed',
        'product_id': event.data?.productVariant?.product?.id,
        'product_title': event.data?.productVariant?.title,
        'product_sku': event.data?.productVariant?.sku,
        'timestamp': event.timestamp,
        'url': event.context.document.location.href
    });
});

For collection view

  1. Create a third GA4 tag
  2. Set Event Name to ‘view_item_list’
  3. Add this code:
analytics.subscribe('collection_viewed', (event) => {
    window.dataLayer.push({
        'event': 'collection_viewed',
        'collection_id': event.data?.collection?.id,
        'collection_title': event.data?.collection?.title,
        'timestamp': event.timestamp,
        'url': event.context.document.location.href
    });
});

Step 3: Create trigger

For each tag, create a trigger:

  1. Click ‘New Trigger’
  2. Choose ‘Custom Event’
  3. Set event names to match your code:
  • ‘page_viewed’
  • ‘product_viewed’
  • ‘collection_viewed’

Then link each trigger to its corresponding tag

Understanding how Shopify event tracking works

Shopify’s analytics system is built on an event-driven architecture. When customers interact with your store, Shopify automatically fires specific events like ‘page_viewed’, ‘product_viewed’, and ‘collection_viewed’. These events contain detailed information about each interaction.

The analytics.subscribe method listens for these events, while the dataLayer acts as a bridge between Shopify and Google Tag Manager, making the data available in a format GTM understands.

Unlimited technical support for website owners

Starting from £1,080 per month.

Just posted

Wave

Enjoy our articles? Join our free list and get more.

Sign Up

Book Discovery Call