How to set up and track enhanced e-commerce in Google Tag Manager

Author:

Setting up and tracking Enhanced E-commerce in Google Tag Manager (GTM) is a powerful way to gain insights into customer behavior throughout the shopping journey on your e-commerce website. Enhanced E-commerce provides more detailed data on user interactions, including product impressions, clicks, add-to-cart events, and purchases, allowing you to optimize your marketing efforts.

This guide will walk you through the steps to set up Enhanced E-commerce tracking using GTM and Google Analytics (GA4 or Universal Analytics).

1. Prerequisites

Before you start, make sure you have:

  • A Google Analytics account set up for your e-commerce site.
  • Google Tag Manager account and container already configured.
  • Basic understanding of GTM and how to implement tags and triggers.
  • E-commerce data layer implemented on your website (if using a custom solution).

2. Understanding Enhanced E-commerce

Enhanced E-commerce tracking allows you to measure key e-commerce interactions, such as:

  • Product Impressions: When a user sees a product in a list or on a page.
  • Product Clicks: When a user clicks on a product.
  • Add to Cart: When a user adds a product to the shopping cart.
  • Checkout: Tracking steps in the checkout process.
  • Purchases: When a user completes a purchase.

By implementing these features, you can analyze the shopping behavior of your users in-depth and improve your e-commerce strategies.

3. Implementing the Data Layer

Before setting up tracking in GTM, ensure that your website is passing relevant e-commerce data through the data layer. The data layer should push events and relevant information about products and transactions.

Example Data Layer Code for Product Impressions

javascript
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'productImpression',
'ecommerce': {
'currencyCode': 'USD', // Currency of the e-commerce
'impressions': [
{
'name': 'Product Name 1',
'id': 'SKU_12345',
'price': '29.99',
'brand': 'Brand Name',
'category': 'Category Name',
'variant': 'Variant Name',
'list': 'Search Results',
'position': 1
},
{
'name': 'Product Name 2',
'id': 'SKU_67890',
'price': '39.99',
'brand': 'Brand Name',
'category': 'Category Name',
'variant': 'Variant Name',
'list': 'Search Results',
'position': 2
}
]
}
});

4. Setting Up Google Tag Manager for Enhanced E-commerce

Step 1: Create a New Tag for Enhanced E-commerce Tracking

  1. Log in to your GTM account and select the container for your website.
  2. Click on Tags in the left sidebar and then New.
  3. Name your tag (e.g., “GA – Enhanced E-commerce – Product Impressions”).
  4. Click on Tag Configuration and select the type of Google Analytics tag you are using:
    • For Universal Analytics: Choose “Google Analytics: Universal Analytics”.
    • For GA4: Choose “Google Analytics: GA4 Event”.
  5. Configure the tag based on your GA type:
    • For Universal Analytics:
      • Set the Track Type to “Event”.
      • Fill in the necessary fields:
        • Category: Ecommerce
        • Action: Product Impression
        • Label: {{Page Path}} (or other relevant data)
        • Enable Non-Interaction Hit if desired.
    • For GA4:
      • Set the Event Name to view_item_list.
      • Add the relevant parameters from the data layer (see step 4 for parameters).

Step 2: Set Up the Trigger for Product Impressions

  1. Create a Trigger: Click on Triggering and then New.
  2. Name your trigger (e.g., “Product Impression Trigger”).
  3. Choose Trigger Type as “Custom Event”.
  4. In the Event Name field, enter productImpression.
  5. Save the trigger.

Step 3: Repeat for Other E-commerce Events

  1. Follow the same steps to create additional tags for tracking:
    • Product Clicks: Set up a tag for when users click on products.
    • Add to Cart: Create a tag to track when users add products to their cart.
    • Checkout Steps: Set up tags for each step of the checkout process.
    • Purchase Events: Create a tag for completed purchases.

Example Data Layer Code for Add to Cart

javascript
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'USD',
'add': {
'products': [{
'name': 'Product Name',
'id': 'SKU_12345',
'price': '29.99',
'brand': 'Brand Name',
'category': 'Category Name',
'variant': 'Variant Name',
'quantity': 1
}]
}
}
});

5. Setting Up Data Layer Variables in GTM

  1. Create Data Layer Variables:
    • Go to Variables in GTM.
    • Click on New.
    • Select Variable Type as Data Layer Variable.
    • For Variable Name, enter the data layer key you want to track (e.g., ecommerce.impressions).
    • Save the variable.
  2. Create Additional Variables: Repeat for other data layer keys relevant to your e-commerce events (e.g., product names, prices, etc.).

6. Testing Your Setup

  1. Enter Preview Mode: Click on the Preview button in GTM.
  2. Open Your Website: In a new tab, navigate to your e-commerce site.
  3. Test E-commerce Events:
    • Trigger the events you set up (e.g., view products, add to cart).
    • Check the GTM debug console to see if the appropriate tags are firing as expected.
  4. Verify in Google Analytics:
    • Log in to your Google Analytics account and check the Real-Time reports to see if the e-commerce events are being recorded correctly.

7. Publishing Your Changes

Once you have tested and confirmed everything is working correctly:

  1. Submit Changes: In GTM, click on Submit.
  2. Add a Version Name and Description: Provide a version name (e.g., “Enhanced E-commerce Setup”) and a description.
  3. Publish the Container: Click Publish to make your changes live.

8. Analyzing Enhanced E-commerce Data in Google Analytics

After you’ve set up Enhanced E-commerce tracking, you can analyze the data in Google Analytics:

  1. Log in to Google Analytics.
  2. Go to Conversions > E-commerce:
    • Check the various reports available, including Overview, Product Performance, Sales Performance, etc.
  3. Use the insights gained to optimize your product offerings, marketing strategies, and overall user experience.

Conclusion

Setting up Enhanced E-commerce tracking in Google Tag Manager provides invaluable insights into user interactions with your e-commerce site. By effectively tracking product impressions, clicks, and purchases, you can optimize your marketing strategies and improve the overall shopping experience for your customers.

Regularly review your e-commerce analytics data to make data-driven decisions and continuously refine your approach to enhance your e-commerce performance.