Skip to content

Instantly share code, notes, and snippets.

@SearchStar
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SearchStar/b2530193a7ab61588d7c to your computer and use it in GitHub Desktop.
Save SearchStar/b2530193a7ab61588d7c to your computer and use it in GitHub Desktop.
Enhanced Ecommerce tracking with GTM
Overview
Google Analytics Enhanced Ecommerce enables product impression, promotion, and sales data to be sent with any of your Google Analytics pageviews and events.
You should review the Enhanced Ecommerce Data Types and Actions section of the Enhanced Ecommerce Dev Guide before you begin. The guide will help you understand which fields are required for each of the ecommerce interactions you want to measure.
https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
The Ecommerce Process
The web page renders the source code which must include the transaction data in the dataLayer object
When the tag which carries the transaction to GA fires, it will look at the dataLayer object
If the data is correct, it will be passed to GA
Other Information
You will need a backend solution that will expose the data for use in the data layer.
You will need to render your dataLayer before your GTM snippet unless you are appending data using the (.push()) to add the data lot the data layer.
The Enhanced Ecommerce plug-in should not be used alongside the Ecommerce (ecommerce.js) plug-in for the same property.
Enhanced eCommerce hits piggy-back on top of existing tags, such as Pageview and Event.
Always include an ‘event’ key in your post-container-snippet pushes, and use this ‘event’ key to fire your tags. Only the most recent dataLayer.push() with the ‘ecommerce’ key is processed by Enhanced eCommerce if you don't use this method.
Measuring Views of Product Details
The following section will show you how to use the data layer to measure the following enhanced ecommerce activities:
Ecommerce Measurement: detail
Accepts Data: list, array of productFieldObjects
Measure a view of product details by pushing a detail action to the data layer, along with one or more productFieldObjects representing the products being viewed:
<script>
// Measure a view of product details. This example assumes the detail view occurs on pageload, and also tracks a standard pageview of the details page.
<script type="text/javascript">
dataLayer.push({
'ecommerce': {
'detail': {
'actionField': {'list': 'Related Product'},
'products': [{
'name': 'Aldo Bar Stool Cream',
'id': '8',
'price': '59.99',
'sku': 'Aldo-Cream'
}]
}
}
});
</script>
See the Tag Configuration for this Example
Tag type : Universal Analytics
Track type : Pageview
Enable Enhanced Ecommerce Features: true
Use Data Layer: true
Basic Settings - Document Path: {{url path}}
Firing Rule: {{event}} equals gtm.js
More Information here: https://developers.google.com/tag-manager/enhanced-ecommerce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment