Google Tag Manager and Google Analytics setup frameworks, using data layers, I step-by-step explain how various information about products and sales transactions can be collected and evaluated in reports, beyond the standard e-commerce event, through the enhanced e-commerce event.
As of July 2023, Universal Analytics (UA) will be replaced by Google Analytics 4 (GA4) property format. After this date, UA properties will no longer be able to process new data. They are expected to become inaccessible by the end of the year. For differences between property types and other operations, please refer to the article titled Universal Analytics (UA) to Google Analytics 4 (GA4). You may also request technical support at (https://calendly.com/dnomia/15min).
Of course, the process of completing a sale and evaluating performance reports is not limited to these. Other topics such as product satisfaction, shipping and delivery process, and post-sale customer support should also be evaluated in a general context1. Our latest case study focuses on how we can link a potential transaction or product return with e-commerce reports2. The name of this event is refund.
Enhanced Ecommerce “refund” Event
IMPORTANT RULES:
- Maintain the original formatting (markdown, HTML tags, links, etc.)
- Keep technical terms and proper nouns as appropriate
- Preserve code blocks and technical syntax exactly
- Maintain the same tone and style
- Only output the translated text, no explanations or comments
The refund event, which is based on product or order cancellation/return, currently relies on unique ID values specified in other event descriptions. Emphasizing that the ID value must be unique in the descriptions ensures smooth return processing while also preventing potential conflicts. Therefore, special attention should be paid during the setup phase, and both the name and the ID field should be as clearly defined as possible. This ensures a practical and seamless return process. Let’s first examine the refund data layer through the purchase/order cancellation scenario. As you can see in the Purchase event, each transaction receives an ID value (e.g., T12345).
// UA
dataLayer.push({
'event' : 'purchase',
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345',
'affiliation': 'Online Store',
'revenue': '59.89',
'tax': '4.90',
'shipping': '5.99',
'coupon': 'SUMMER2018'
},
'products': [{
// product details
}]
}
}
});
// GA4
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'purchase': {
'transaction_id': 'T12345',
'affiliation': 'Online Store',
'value': '35.43',
'tax': '4.90',
'shipping': '5.99',
'currency': 'EUR',
'coupon': 'SUMMER_SALE',
'items': [{
// product details
}]
}
}
});
The ID value for UA (id) and the transaction_id value for GA4 are separately provided below.
// UA
dataLayer.push({
'event' : 'purchase',
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345'
}
}
}
});
// GA4
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'purchase': {
'transaction_id': 'T12345'
}
}
});
This ID value ensures that our entire transaction is canceled and reflects to our reports that the refund has been processed to the customer. In summary, our refund data layer will look like this:
window.dataLayer = window.dataLayer || [];
// UA
dataLayer.push({
'ecommerce': {
'refund': {
'actionField': {
'id': 'T12345' // Unique Transaction ID / Type: string (required)
}
}
}
});
// GA4
dataLayer.push({
'event': 'refund',
'ecommerce': {
'transaction_id': 'T12345' // Unique Transaction ID / Type: string (required)
}
});
This way, all products within the transaction are reported to Google Analytics as having been refunded. Now, what if we only want to refund certain product quantities or specific items? In that case, we can use the relevant data layer with the following additions:
// UA
dataLayer.push({
'event': 'refund',
'ecommerce': {
'refund': {
'actionField': { 'id': 'T12345' }, // Unique Transaction ID / Type: string (required)
'products': [
{ 'id': 'P4567', 'quantity': 1 }, // Unique Product ID and Product Quantity
{ 'id': 'P8901', 'quantity': 2 }
]
}
}
});
// GA4
dataLayer.push({
'event': 'refund',
'ecommerce': {
'transaction_id': 'T12345', // Unique Transaction ID / Type: string (required)
'items': [
{ 'item_id': 'P4567', 'quantity': 1 }, // Unique Product ID and Product Quantity
{ 'item_id': 'P8901', 'quantity': 2 }
]
}
});
In the example above, let’s assume two units of the product with ID P4567 have been purchased. In this case, one unit of the relevant product with ID P4567 will be refunded. If only one unit of the relevant product has been purchased, the product will be fully refunded. The same applies to the product with ID P8901. From a completed transaction, one or more products can be reported as refunded via their respective IDs. Of course, we can also provide detailed product return information.
// UA
dataLayer.push({
'event': 'refund',
'ecommerce': {
'refund': {
'actionField': {
'id': 'T12345'
},
'products': [{
'id': 'P4567',
'name': 'Newage T-Shirt',
'price': '31.00',
'quantity': 1
}]
}
}
});
// GA4
dataLayer.push({
'event': 'refund',
'ecommerce': {
'transaction_id': 'T12345',
'items': [{
'item_name': 'Donut Friday Scented T-Shirt',
'item_id': '67890',
'price': '33.75',
'item_brand': 'Google',
'item_category': 'Apparel',
'item_category_2': 'Mens',
'item_category_3': 'Shirts',
'item_category_4': 'Tshirts',
'item_variant': 'Black',
'item_list_name': 'Search Results',
'item_list_id': 'SR123',
'index': 1,
'quantity': '1'
}]
}
});
In the example above, both the transaction ID and product ID are specified, along with product details and the "event": "refund" indicating a refund action. You can generate daily transaction reports to send email summaries of the total transactions that occurred at the end of the day, or set up alerts to detect potential positive and/or negative changes in average transaction value. However, it’s crucial to remember that you should not overlook the need to report potential refunds in addition to daily actions, and evaluate them through weekly and monthly reports. Remember, you are not required to specify the full transaction amount in a refund case. For instance, in a transaction specified as 'revenue': '59.89', the product price and/or the revenue value such as 'revenue': '40.89' may be redefined, allowing for potential cost or coupon value deductions.
For additional details and related events in enhanced e-commerce, please refer to Enhanced Ecommerce, Google Analytics Goals and Funnel Actions, Google Tag Manager dataLayer and E-Commerce Events, Google Analytics E-Commerce Reports and Event Setups, and the help pages for Google Analytics / GTM UA3 and GA44.
*[GTM]: Google Tag Manager
*[UA]: Universal Analytics
*[GA4]: Google Analytics 4