GTM Setup for E-commerce: Step-by-Step Guide

published on 11 March 2025

Setting up Google Tag Manager (GTM) for your e-commerce store helps you track important customer actions like product views, add-to-cart events, and purchases - all without constantly editing your site’s code. Here's a quick overview of what you'll learn:

  • Benefits of GTM: Simplifies tag management, improves data accuracy, and enables real-time updates.
  • Setup Essentials: Create a GTM account, add GTM code to your site, and configure Google Analytics 4 (GA4) tags.
  • Event Tracking: Monitor key actions like checkout steps, completed purchases, and refunds.
  • Testing & Fixes: Use GTM’s Preview mode and GA4’s Debug View to ensure accurate tracking.

This guide walks you through the entire process, from account setup to advanced event tracking, and offers tips to troubleshoot common issues effectively.

How to Set up E-Commerce Tracking in Google Analytics 4 using GTM

Google Analytics 4

Setup Requirements

Make sure you have the right tools and permissions ready before diving into GTM (Google Tag Manager) setup.

Set Up GTM Account

Getting your GTM account ready requires a structured approach. Here’s what you’ll need:

Requirement Description Purpose
Google Account Active Google Workspace or personal account Access to the GTM dashboard
Website Access Admin-level access to your e-commerce platform To implement the GTM code
Analytics Account Google Analytics 4 property For setting up data collection

GTM operates with a hierarchy: Account > Container > Workspace. Be sure to create a specific container for your store to simplify tracking and organization.

Add GTM Code to Your Website

The way you add GTM code depends on the platform you’re using. You’ll need to insert two key snippets:

  1. GTM Container Snippet
    Add this snippet to the <head> section of every page. It loads your GTM container and ensures tags fire immediately.
  2. GTM No-Script Snippet
    Place this snippet right after the <body> tag. This ensures tracking works even if JavaScript is turned off.

Here’s how to implement these snippets on popular e-commerce platforms:

Shopify

  • Go to Online Store > Themes.
  • Edit the theme code.
  • Locate the file named theme.liquid.
  • Add the GTM container snippet in the <head> section.
  • Insert the no-script snippet after the <body> tag.

WooCommerce

  • Log in to your WordPress admin dashboard.
  • Edit the header.php file in your theme.
  • Place the container snippet before the closing </head> tag.
  • Add the no-script snippet right after the <body> tag.

Magento

  • Navigate to Admin Panel > Content > Design > Configuration.
  • Select your store view.
  • Insert the GTM code in both the HTML Head and Scripts sections.

You can also connect tools like Google Analytics, Hotjar, or Adobe Analytics (refer to the Marketing Analytics Tools Directory) to gain deeper insights into your e-commerce performance.

Before moving on to setting up advanced e-commerce events, use GTM’s Preview mode to ensure everything is installed correctly.

E-commerce Tracking Setup

Set up Google Tag Manager (GTM) to monitor customer activity using tags, variables, and triggers.

Set Up a GA4 Tag

Start by creating a GA4 configuration tag to collect e-commerce data:

  1. Create a Configuration Tag Go to Tags > New and choose "Google Analytics: GA4 Configuration." Enter your GA4 Measurement ID and include key settings like:
    {
      "send_page_view": true,
      "currency": "USD"
    }
    
    By default, send_page_view is set to true and the currency is set to USD.

Next, define the variables needed for tracking transaction details.

Create E-commerce Variables

Define variables to capture transaction information effectively:

  • ecommerce.transaction_id: A unique ID for each order
  • ecommerce.items: An array with product details
  • ecommerce.value: The total transaction amount
  • calculateTax: Code to calculate applicable taxes
  • getShippingInfo: Code to retrieve shipping details

Once these variables are ready, you can push event data to the data layer.

Track Basic E-commerce Events

Push data for important e-commerce events to the data layer:

  1. View Item Example code:
    dataLayer.push({
      'event': 'view_item',
      'ecommerce': {
        'items': [
          {
            'item_id': 'SKU_12345',
            'item_name': 'Product Name',
            'price': 29.99
          }
        ]
      }
    });
    
  2. Add to Cart & Remove from Cart Use triggers to push these events:
    • Add to Cart:
      dataLayer.push({
        'event': 'add_to_cart',
        'ecommerce': {
          'currency': 'USD',
          'value': 29.99,
          'items': [
            {
              'item_id': 'SKU_12345',
              'quantity': 1
            }
          ]
        }
      });
      
    • Remove from Cart:
      dataLayer.push({
        'event': 'remove_from_cart',
        'ecommerce': {
          'items': [
            {
              'item_id': 'SKU_12345'
            }
          ]
        }
      });
      

Finally, use GTM's Preview Mode to confirm that these events are working as expected.

sbb-itb-5174ba0

Advanced Event Setup

Taking your e-commerce tracking to the next level, advanced event tracking lets you monitor customer behavior from the checkout process all the way to completing a purchase.

Track Checkout Process

To track the checkout process, start by triggering a custom event when the checkout begins:

dataLayer.push({
  'event': 'begin_checkout',
  'ecommerce': {
    'currency': 'USD',
    'value': 159.99,
    'items': [{
      'item_id': 'SKU_789',
      'item_name': 'Premium Headphones',
      'price': 159.99,
      'quantity': 1
    }],
    'checkout_step': 1
  }
});

You can also track key steps in the checkout process, such as:

  • Shipping information entry
  • Payment method selection
  • Order review
  • Final confirmation

Once you've captured these steps, move on to recording the details of completed purchases.

Track Purchase Events

For tracking completed transactions, use a purchase event that includes all essential order details. Here's an example:

dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'transaction_id': 'T_12345',
    'currency': 'USD',
    'value': 159.99,
    'tax': 12.99,
    'shipping': 8.99,
    'items': [{
      'item_id': 'SKU_789',
      'item_name': 'Premium Headphones',
      'price': 159.99,
      'quantity': 1
    }]
  }
});

You can also include additional custom variables, such as the order subtotal, applied discounts, payment method, and shipping details, to provide a more detailed view of each transaction.

Testing and Fixes

Once your e-commerce tracking is set up in GTM, testing is a must to ensure everything works as it should. Here's how to test effectively and troubleshoot common problems.

Test with Preview Mode

Start by using GTM's Preview mode. Here's how:

  1. Enter your website URL and activate Preview mode.
  2. Open your e-commerce site in a new tab.
  3. Perform test transactions and check the Preview pane for key events like begin_checkout and purchase.

Key areas to focus on:

  • Data Layer Events: Verify that events like begin_checkout and purchase trigger as expected.
  • Variable Values: Ensure details such as price, currency, and product data display correctly.
  • Tag Firing Order: Confirm tags fire in the correct sequence during the checkout process.

Check GA4 Data

Once events are firing in Preview mode, check if the data is making it to GA4. Here's what to do:

  1. Open the Real-Time report in GA4.
  2. Perform test transactions on your site.
  3. Verify events appear in the report.
  4. Use the Debug View to inspect detailed event parameters.

Pay attention to:

  • Transaction values aligning with your store prices.
  • Complete and accurate product data.
  • Consistent currency codes.
  • Proper flow of user and session data.

Fix Common Issues

If testing reveals problems, here are some typical issues and how to address them:

Issue Common Cause Solution
Events not firing Incorrect trigger conditions Adjust trigger settings and test with broader criteria.
Missing transaction data Incorrect dataLayer setup Check that your dataLayer push matches GA4 specs.
Duplicate purchases Tags firing multiple times Set the tag to fire only once per event.
Invalid currency codes Formatting problems Use ISO-standard codes like USD or EUR.

For additional fixes:

  • Use custom JavaScript variables to clean up price formats.
  • Set up lookup tables to standardize product categories.
  • Apply regular expressions in triggers to handle event name variations.

Testing and troubleshooting might take time, but it’s worth the effort to ensure accurate data collection.

Analytics Tools Guide

Once you've set up GTM events, it's time to expand your analytics capabilities with specialized tools.

Explore the Tools Directory

The Marketing Analytics Tools Directory organizes top e-commerce analytics tools into categories to simplify your search. Here's a quick breakdown:

Category Example Tools Key Features
User Behavior Hotjar, FullStory Session recordings, funnels
Attribution Windsor.ai, Rockerbox Multi-channel attribution
Real-time Analytics Keen.io, Woopra Live data streams
Predictive Analytics MadKudu, Amplitude AI-based forecasting

Look for tools that offer strong integrations, advanced data features, real-time tracking, and transparent pricing.

Tools That Pair Well With GTM

GTM excels in event tracking, but pairing it with other tools can reveal deeper insights into customer behavior.

Real-Time Customer Journey Analysis:

  • Woopra: Tracks customer journeys across multiple touchpoints.
  • Quantum Metric: Provides website analytics to improve user experiences.
  • Contentsquare: Uses AI to analyze customer behavior.

Advanced E-Commerce Attribution:

  • OWOX BI: Combines marketing data from various channels.
  • Dreamdata: Links marketing efforts directly to sales outcomes.
  • Funnel.io: Simplifies marketing data collection through automation.

Privacy-First Analytics:

  • Fathom Analytics: Offers GDPR-compliant tracking solutions.
  • Piwik PRO: Delivers enterprise-grade analytics with privacy features.
  • Matomo: Allows on-premise hosting for complete data control.

For example, while GTM tracks events effectively, tools like Smartlook can add depth by showing session recordings. This helps you understand why users abandon their carts during checkout. Choose tools that align with your goals and complement GTM's capabilities.

Summary

Setting up Google Tag Manager (GTM) for e-commerce requires attention to detail. A well-executed GTM setup allows for accurate tracking of e-commerce activity. This guide breaks down the key steps for implementing GTM on your e-commerce platform.

Main Points

Key steps for a successful GTM setup:

  • Account Setup and Integration
    • Create a GTM account specifically for your site.
    • Add the GTM code to your website's header.
    • Use Preview mode to ensure the installation works.
    • Configure GA4 tags to start collecting data.
  • E-commerce Event Tracking
    • Define the variables you need to track.
    • Monitor key actions like product views, cart interactions, and checkout progress.
    • Track completed purchases and refunds.
  • Testing and Maintenance
    • Use Preview mode to check data accuracy.
    • Confirm that data flows correctly into GA4.
    • Regularly monitor tracking and fix any issues promptly.
    • Update your configurations as needed.
  • Improving Analytics
    • Add extra analytics tools for deeper insights.
    • Set up custom variables tailored to your needs.
    • Implement cross-domain tracking if required.
    • Enhance your tracking setup for advanced reporting.

Related Blog Posts

Read more