As a continuation of the article “Data Layer (dataLayer)”, in this post I will discuss enhanced ecommerce (enhanced e-commerce) events/actions (events) using data layer information.
I previously created similar content for Facebook Events. For e-commerce websites, data processing via Facebook and Google’s data layer will be implemented.
Below you can see detailed information about e-commerce events we’ll be using based on Google Analytics. However, there’s one point I’d like to emphasize: data layer operations must be defined prior to the GTM snippet. The data required by the mappings inside GTM must be ready at that time. Otherwise, the events will not send data as planned.
You can find support requests for Google Tag Manager here.
On the other hand, having a basic understanding of the GTM standard events (gmt.load, gtm.js, and gtm.dom) is also beneficial. You can review the “Data Layer (dataLayer)” article regarding these two topics. Another point to note is that if our window.dataLayer.push code appears before the GTM snippet, we must establish a window relationship using window.dataLayer = window.dataLayer || []. Otherwise, a JavaScript error will occur because the dataLayer object is not defined.
window.dataLayer = window.dataLayer || [];
- While working with a page template, always check whether dataLayer has been defined prior and, if necessary, initialize it as a new array.
- When performing dataLayer operations, if actions occur after the snippet, use the
push()method. - If dataLayer has been created but has not been initialized as an array, the operation
window.dataLayer = window.dataLayer || [];will not take effect. This is a very common error scenario. - Ensure that trigger (activation) operations for the above situations (especially within GTM) are processed before the GTM snippet in the loading sequence.
Enhanced E-Commerce Events
The Google documentation for developers on Google Tag Manager, specifically the “Enhanced Ecommerce” section, is valuable for staying updated on potential future changes and enhancements1. I will also explain how you can view relevant data from your Google Analytics account within the context of these events. If you’d like to review the general overview of these reports, you can explore the Enhanced Ecommerce reports page2. Additionally, I’ll provide you with access to the official Google-defined product categorizations for the Product Category (category) used in product and purchase events, available on the google_product_category: Definition page3.
Throughout all these processes, you can track your actions and detect potential errors using the Google Tag Assistant extension. Another extension I believe will be useful to you is dataslayer, with which you can also monitor your data layer operations via the Console and evaluate information events6. An example of an impression event (multiple impressionFieldObjects can be added, and you can gain information about multi-product delivery via the impressions connection) can be sent as follows:
// UA
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'currencyCode': '[currency-code]', // Currency Code (TRY, USD, EUR, etc.) / Type: string (optional)
'impressions': [{
'id': '[unique-product-id]', // Unique Product ID / Type: string (required)
'name': '[product-name]', // Product Name / Type: string (required)
'price': '[product-price]', // Product Price / Type: numeric (required)
'brand': '[product-brand]', // Product Brand / Type: string (optional)
'category': '[product-category]', // Product Category / Type: string (optional)
'position': '[product-list-position]', // Product List Position / Type: numeric (optional)
'list': '[product-list]' // Product's List / Type: string (optional)
}]
}
});
// GA4
dataLayer.push({
'event': 'view_item_list',
'ecommerce': {
'items': [{
'item_name': '[product-name]', // Product Name / Type: string (required)
'item_id': '[unique-product-id]', // Unique Product ID / Type: string (required)
'price': '[product-price]', // Product Price / Type: numeric (required)
'item_brand': '[product-brand]', // Product Brand / Type: string (optional)
'item_category': '[product-category]', // Product Category / Type: string (optional)
'item_category_2': '[product-subcategory-1]', // Product Subcategory / Type: string (optional)
'item_category_3': '[product-subcategory-2]', // Product Subcategory / Type: string (optional)
'item_category_4': '[product-subcategory-3]', // Product Subcategory / Type: string (optional)
'item_variant': '[product-variant]', // Product Variant / Type: string (optional)
'item_list_name': '[product-list-name]' // Name of the list where the product appears / Type: string (optional)
'item_list_id': '[product-list-id]' // ID of the list where the product appears / Type: numeric (optional)
'index': '[product-list-order]' // Product listing order / Type: numeric (optional)
'quantity': '[product-quantity]' // Product quantity / Type: numeric (required)
}]
}
});
I’ve added the requirement that either id or name is required for UA, and either item_id or item_name is required for GA4; providing just one of these (product ID or product name) is sufficient. Ideally, both fields should be used. When the product name is not defined, the product name column in reports will display (not set) in the corresponding cell. The category field includes Google’s predefined category definitions. For UA, an example category definition is as follows: Male/Clothing/Sports. A hierarchy can be established within the category definition ranging from 1 to 5 levels. In this example, the following category levels are defined: Product Category Level 1: Male, Product Category Level 2: Clothing, Product Category Level 3: Sports. GA4 also receives the category information. Therefore, it is necessary to specify the category levels separately. In Google Analytics’ standard e-commerce reports, you can define product category levels under E-commerce > Secondary Dimension and include them in your reports.
After implementing this example, you can view the impression data (product list views, product list clicks, product list name, product list location, product, product SKU, etc.) through the path: Google Analytics > Property > View > Conversions > E-commerce > Product List Performance.
Below is the list of relevant events/actions. Each event includes its own reporting section and relevant additional tips. Since data layer usage is considered in these actions, I will address gtag ecommerce events in a separate article.
- Impressions
- Product Click
- Promotion Click
- Promotion View
- Product Detail
- Add to Cart
- Remove from Cart
- Checkout
- Purchase
- Refund