Here is the official GTM dataLayer GA Enhanced Ecommerce spec:
https://developers.google.com/tag-manager/enhanced-ecommerce
Transactions are referred to as "purchase":
https://developers.google.com/tag-manager/enhanced-ecommerce#purchases
<script>
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345', // Transaction ID. Required for purchases and refunds.
'affiliation': 'Online Store',
'revenue': '35.43', // Total transaction value (incl. tax and shipping)
'tax':'4.90',
'shipping': '5.99',
'coupon': 'SUMMER_SALE'
},
'products': [{ // List of productFieldObjects.
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1,
'coupon': '' // Optional fields may be omitted or set to empty string.
},
...
The spec documentation isn't of the highest quality, so for a happy implementation I recommend the following best practices
dataLayer.push not working after GTM script
- Always initialize the dataLayer
- Always set the "event" property
To facilitate your life even more, you can do:
- Event =
ecommerce_{action}
- Category = Ecommerce
- Action = {action} (eg purchase, click...)
The event naming convention will allow you to create 1 single GTM trigger (Event REGEX ecommerce_.*
) and therefore 1 single tag to capture all your Ecommerce events (having to create separate triggers/tags for each Ecommerce action is unnecessary and painful)
Once that's done, create a GTM Google Analytics Event tag with the above trigger, and enable Ecommerce in the GA settings:
