As ecommerce websites become increasingly popular, it's essential to track user behavior and conversion rates to optimize your website for maximum profitability. One of the most effective tools for tracking ecommerce performance is Google Tag Manager (GTM). In this article, we will discuss how to use GTM to track ecommerce variables using the dataLayer and variables.

What is Google Tag Manager (GTM)?

Google Tag Manager is a free tool from Google that allows you to manage and deploy marketing tags (snippets of code) on your website without having to modify the code directly. This can be incredibly helpful for tracking user behavior and ecommerce transactions, as it reduces the need for custom coding and can speed up the tracking implementation process.

The Benefits of GTM for Ecommerce Websites

Using GTM can provide several benefits for ecommerce websites, including:

  • Centralized tracking: GTM allows you to manage all of your tracking tags in one place, which can make it easier to troubleshoot and manage your tracking.
  • Faster tracking implementation: Since GTM doesn't require custom coding, you can deploy tracking tags faster than if you had to modify the website's code directly.
  • Flexibility: GTM is highly customizable, which means that you can track a wide range of user behaviors and actions, including ecommerce transactions.

Using the DataLayer to Track Ecommerce Variables

The dataLayer is a JavaScript object that contains information about user interactions on your website. You can use the dataLayer to track a wide range of user behaviors and actions, including ecommerce transactions. To track ecommerce variables using the dataLayer, you need to push an ecommerce dataLayer event to the dataLayer.

Here's an example of an ecommerce dataLayer push:

                    dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'purchase': {
      'actionField': {
        'id': '12345',
        'affiliation': 'Example Store',
        'revenue': '100.00',
        'tax': '10.00',
        'shipping': '5.00',
        'coupon': 'SUMMER'
      },
      'products': [{
        'id': 'SKU123',
        'name': 'Product Name',
        'price': '25.00',
        'quantity': 4
      }]
    }
  }
});
                  

As you can see, this push contains several ecommerce variables, such as the product ID, name, price, and quantity.

Using Variables in GTM

To use the ecommerce variables in GTM, you need to create a Data Layer Variable for each variable that you want to track. For example, to track the product ID, you would create a Data Layer Variable with the Data Layer Variable Name "ecommerce.purchase.products.id".

Once you have created the Data Layer Variables, you can use them in your tags and triggers. For example, you could create a Google Analytics tag that uses the ecommerce variables to track purchases. Or, you could create a trigger that fires when the "purchase" event is pushed to the dataLayer.

In ecommerce tracking, Variables can be particularly useful for tracking product details, such as product name, price, and ID. To use Variables in ecommerce tracking, follow these steps:

  • Create a Data Layer Variable: First, create a Data Layer Variable that extracts the product details from the dataLayer push. For example, you could create a Data Layer Variable with the Data Layer Variable Name "ecommerce.purchase.products.id" to track the product ID.
  • Create a Custom Variable: Next, create a Custom Variable that uses the Data Layer Variable to extract the product details. For example, you could create a Custom Variable with the Variable Type "Data Layer Variable" and the Data Layer Variable Name "ecommerce.purchase.products.id".
  • Use the Custom Variable in a Tag: Finally, use the Custom Variable in a tag that tracks ecommerce transactions. For example, you could create a Google Analytics tag that tracks purchases and includes the Custom Variable in the product details section of the tag.

By using Variables in this way, you can make your ecommerce tracking more efficient and maintainable, as you won't have to repeat the same product details across multiple tags and triggers. Instead, you can define the product details in a Variable, and then reuse that Variable across multiple tags and triggers.

Using Google Tag Manager to track ecommerce variables can provide several benefits for ecommerce websites, including centralized tracking, faster tracking implementation, and flexibility. By using the dataLayer and variables, you can track a wide range of user behaviors and actions, including ecommerce transactions. If you haven't already implemented GTM on your ecommerce website, now is the time to start.