This article is in conjunction with the article ecommerce tracking in Google Analytics – complete guidewhere I introduce the concept of ecommerce tracking in Google Analytics and explain various ecommerce terms in great detail.
In the current article, I will show you how to install enhanced ecommerce tracking via Google Tag Manager (GTM).
Follow the steps below to implement enhanced ecommerce tracking via GTM:
Step-1: Integrate your Shopping Cart with Google Tag Manager
This involves adding a ‘GTM container code’ on each page of your ecommerce website immediately after the opening body tag <body>.
If you are using a custom shopping cart, ask your developer to add the GTM container code immediately after the opening body tag <body> on all website pages.
If you use a third-party shopping cart like Shopify, you may need to refer to their help documentation or ask their customer support about “where exactly to add the GTM container code?”. You would most likely need to edit some template files and add your GTM code there.
Then there are shopping carts like Magento, where you do not need to add any GTM container code. You just supply your container ID, and the GTM is automatically installed on your website.
Bear in mind that many shopping carts still do not integrate with GTM. If you are using one of such shopping carts, you should stop reading this article right now and switch your shopping cart to one that integrates with GTM, preferably Shopify.
Step-2: Deploy Universal Analytics Tracking via GTM
Create and publish a Universal Analytics tag on your website via GTM, and then remove the corresponding hard-coded Google Analytics tracking code from all of the website pages:
It is important that you remove the hard-coded GA Tracking Code, otherwise your GA tracking code will fire twice, once via GTM and once via hard-coded tag, which could inflate your GA data.
Some shopping carts like Shopify do not let you remove the hard-coded Google Analytics tracking code from your website.
In that case, do not deploy the Universal Analytics tag on your website via GTM, otherwise your GA tracking code will fire twice, once via GTM and once via the hard-coded tag, which could inflate your GA data.
So before you deploy a Universal Analytics tag on your website via GTM, make sure you can remove the hard-coded GA tracking code from your website.
Step-3: Turn on Ecommerce and Enable Enhanced Ecommerce Reporting in Google Analytics
Google Analytics will report ecommerce data in your reporting view only when the ecommerce tracking has been turned on at the view level.
Enabling enhanced ecommerce reporting will also provide you with important steps in standard purchase funnels, like product view, add to cart, checkout steps and transaction details.
Follow the steps below:
Step-3.1: Login to your Google Analytics account and then navigate to the ‘Admin’ section of your view:
Step-3.2: Click on the ‘Ecommerce settings’ link (under the ‘view’ column):
Step-3.3: Switch the toggle button to ‘ON’ (under ‘Enable Ecommerce Status’) and then switch the toggle button to ‘ON’ (under ‘Enable Enhanced Ecommerce Reporting’):
Step-3.4: Click on ‘Save’:
If you have multiple steps in the checkout section, you can add them as funnel steps (we will discuss them later in the article). Your GA reporting view is now ready to collect and report on enhanced ecommerce data.
Step-4: Enable Ecommerce Tracking in your Shopping Cart (optional)
Many shopping carts these days provide built-in ecommerce tracking. This tracking is either automatically enabled or you need to enable it manually.
For example, in the case of Shopify, ecommerce tracking is already enabled for all Shopify customers. Shopify does not use any data layer for ecommerce tracking. So whether or not you use GTM, your ecommerce tracking is already installed and running. Once you have turned on ecommerce tracking in Google Analytics, you should start seeing the ecommerce data from Shopify in your GA reports. You don’t need to do anything else.
Then there are shopping carts like Magento, where you may need to purchase an extension to install ecommerce tracking via GTM. For example, Magento provides built-in data layer support for transaction data via Google Tag Manager Magento Connect extension:
Once you have installed this extension and enabled it, it will automatically create a data layer for you on the order confirmation page and populate it with transaction data. That’s it! Your ecommerce tracking is now enabled via GTM. You don’t need to do anything else.
However, if your shopping cart does not provide built-in data layer support for transaction data or pre-built ecommerce tracking, or you use a custom shopping cart, follow the next step.
To cut a long story short, data layer variables enable Google Tag Manager to read values from your data layer implementation and pass those values to tags, triggers, and other variables. A data layer object comprises a list of key/value pairs.
To create a data layer, copy-paste the following code just after the opening <head> tag before the Google Tag Manager container code.
<script>
dataLayer=[];
</script>
Congratulations, you just created your first data layer.
Enhanced Ecommerce Events:
Enhanced ecommerce events enable the measurement of user interactions with products on ecommerce websites across the user’s shopping experience, including:
Product impressions
Product clicks
Viewing product details
Adding a product to a shopping cart
Initiating the checkout process
Transactions
To track enhanced ecommerce events, we need to pass these events to dataLayer using dataLayer.push method. The following section will give you more details on measuring enhanced ecommerce activities.
Measuring Product Impression
Whenever the user lands on your website’s home page or product category page, the user is shown multiple products. Here we measure which products are shown to the user using product impression events.
Ask your developer to fire the code below whenever the page loads with multiple products.
<script>
// Measures product impressions and also tracks a standard
// pageview for the tag configuration.
// Product impressions are sent by pushing an impressions object
// containing one or more impressionFieldObjects.
dataLayer.push({
'ecommerce': {
'currencyCode': 'US Dollor', // Local currency is optional.
'impressions': [
{
'name': 'T-Shirt', // Name or ID is required.
'id': '2321',
'price': '11.25',
'brand': 'Brandname',
'category': 'Apparel',
'variant': 'Gray',
'list': 'Search Results',
'position': 1
},
{
'name': 'Mens T-Shirt',
'id': '6566',
'price': '73.75',
'brand': 'Brand Name',
'category': 'Apparel',
'variant': 'Black',
'list': 'Search Results',
'position': 2
}]
}
});
</script>
The above code will send the product impression event to the data layer and now pull this data and send it to Google Tag Manager.
Ask your developer to add the modified data layer code (data layer code with server-side script) just after the opening body tag (<head>) and before the Google Tag Manager container code. This will automatically update the dataLayer with the current product available on the page.
Measuring Product Clicks
To measure product clicks, ask your developer to fire the below code whenever the user clicks on the product link.
<script>
dataLayer.push({
'event': 'productClick',
'ecommerce': {
'currencyCode': ''United States Dollar',
'add': { // 'add' actionFieldObject measures.
'products': [{ // adding a product to a shopping cart.
'name': 't-shirt',
'id': '12345',
'price': '16.25',
'brand': 'brandname',
'category': 'mens',
'variant': 'black',
'position': 5
}]
}
}
});
</script>
Measuring Product Detail Views
The next step is to measure product detail views by the users. This event is fired on page load whenever the product detail page is loaded along with other product field objects like price, colour, product id, etc.
Ask your developer to fire the below code whenever the product detail page loads.
The above code will send the product view event to the data layer along with other product details, which can be pulled using GTM and sent to Google Analytics.
Measuring Additions or Removals from a Shopping Cart
In a standard purchase funnel, the user may add or remove products to the cart and measuring these events is also important. Just like we did dataLayer push events for product impression and product detail view, you can also implement the cart events.
Ask your developer to fire the below code whenever the product is added to the cart.
<script>
dataLayer.push({
'event': 'addtocart',
'ecommerce': {
'currencyCode': ''United States Dollar',
'add': { // 'add' actionFieldObject measures.
'products': [{ // adding a product to a shopping cart.
'name': 't=shirt',
'id': '12345',
'price': '16.25',
'brand': 'brandname',
'category': 'mens',
'variant': 'black',
'quantity': 2
}]
}
}
});
</script>
The above code will send add to cart event to the data layer along with other product details.
Similarly, fire the code below when the user removes any product from the cart.
'products': [{ // removing a product to a shopping cart.
'name': 't-shirt',
'id': '12345',
'price': '16.25',
'brand': 'brandname',
'category': 'mens',
'variant': 'black',
'quantity': 1
}]
}
}
});
</script>
Measuring Checkout Steps
To measure the checkout process that the user follows once he clicks on the checkout button and provides details like shipping address and payment method and sometimes uses coupon codes as well (if you have it), we use checkout event and push it to dataLayer.
You can add multiple checkout events if your checkout process contains multiple steps like adding a shipping address, selecting a payment method etc.
Ask your developer to fire the below code when the checkout process starts.
<script>
dataLayer.push({
'event': 'checkout',
'ecommerce': {
'currencyCode': ''United States Dollar', //replace with user currency
'checkout': {
'actionField': {'step': 1},
'products': [{
'name': 't-shirt',
'id': '12345',
'price': '16.25',
'brand': 'brandname',
'category': 'mens',
'variant': 'black',
'quantity': 1
}]
}
}
})
</script>
If you have multiple steps in the checkout, you can fire the checkout event again and mention the step number in ‘actionField’: {‘step’: 2} in the above code.
Additionally, you will also need to configure Funnel steps in Google Analytics. You can give a descriptive name to each of the steps in the checkout process.
To configure these names, visit the Admin section of the Google Analytics Web Interface, select the view (profile) and click on Ecommerce Settings. Follow the ecommerce set-up instructions to label each checkout step you want to track like below:
Measuring Transactions or Purchase Events
Purchase event is the final step in the enhanced ecommerce funnel. Ask your developer to fire the below code whenever the transaction happens. You can also pass the purchase event on the order confirmation page or thank you page load.
<script>
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'currencyCode': 'United States Dollar', //replace with user currency
'purchase': {
'actionField': {
'id': 'T12345', // Transaction ID. Required for purchases and refunds.
'revenue': '250', // Total revenue including tax.
'tax':'',
'shipping': '',
'coupon': '' // Optional fields may be omitted or set to empty string.
},
'products': [{ // List of productFieldObjects.
'name': 't-shirt', // Name or ID is required.
'id': '12345',
'price': '16.25',
'brand': 'brandname',
'category': 'mens',
'variant': 'Black',
'quantity': 1
},
]
}
}
});
</script>
As of now, we have sent enhanced ecommerce events to dataLayer only. Since all these events are codes to be executed on corresponding conditions, copy-paste all the data layer code into a notepad file and send it to your developer. Ask them to write some server-side script (like PHP) that automatically retrieves ecommerce data from your shopping cart software and populates the various fields (server variables) of your data layer code with the actual ecommerce data.
Tell them to keep the following points in mind while working on the data layer code:
Data layer variable names are case-sensitive. So keep the names of the data layer variables intact. For example, use ‘transactionId’ instead of ‘TransactionId’, ‘TransactionID’ or something else. Otherwise, ecommerce tracking may not work.
Do not use currency identifiers (like $, £, €, etc.) in the numeric fields and/or separate numbers in the numeric fields by a comma. This can create tracking issues.
Make sure that the data layer code is not placed after the Google Tag Manager container code; in that case, ecommerce tracking may not work.
The next step will be configuring the Google Tag Manager to send data to Google Analytics.
Step-6: Configure your Google Tag Manager for Enhanced Ecommerce Tracking
#6.1 Log into your Google Tag Manager account and create a new tag with the following specifications for every enhanced ecommerce event.
Tag for Measuring Product Impression:
Tag Name: Ecommerce Product Impression
Tag Type: Universal Analytics
Track Type: Page View
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: Product Impression
Trigger Type: Pageview
This Trigger fires on: Some Pageviews
Fire this trigger when an Event occurs and all of these conditions are true
url equals <enter the URI of your product impression page here>
Note: If you have multiple Page URL product Impression, you can use regex for providing the list of URL
Here I am using regex as “/|category/” in which “/” represents the home page where I have multiple products and “|” represents OR condition, and the next part is “category/”, which is my category page URL and have products listed there.
Your final tag may look like the one below:
Tag for Measuring Product Clicks
Tag Name: eCommerce Product Clicked
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Product Click
Event Label: {{product_clicked}} Note: Here, I am using a variable containing the name of the product clicked.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: Product Clicked
Trigger Type: Custom Event
Event name: productClick
This trigger will fire when the custom event equals ‘productClick’. Your final tag may look like the one below:
Tag for Measuring Product Detail Views
Tag Name: eCommerce Product Detail
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Product Detail View
Event Label: {{product_detail}} Note: Here, I am using a variable which contains the name of the product which is viewed.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: Product Detail View
Trigger Type: Custom Event
Event name: productView
This trigger will fire when the custom event equals ‘productView’. Your final tag may look like the one below:
Tag for Measuring Additions to a Shopping Cart
Tag Name: eCommerce Add to Cart
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Add to Cart
Event Label: {{product_name added to cart}} Note: Here, I am using a variable which contains the name of the product which is added to the cart.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: ecommerce add to cart
Trigger Type: Custom Event
Event name: addtocart
This trigger will fire when the custom event equals ‘addtocart’. Your final tag may look like the one below:
Tag for Measuring Removal from Shopping Cart
Tag Name: Ecommerce- removeFromCart
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Remove From Cart
Event Label: {{product_name removeFromcart}} Note: Here, I am using a variable that contains the product’s name removed from the cart.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: ecommerce remove from cart
Trigger Type: Custom Event
Event name: removeFromCart
This trigger will fire when the custom event equals ‘removeFromCart’. Your final tag may look like the one below:
Tag for Measuring Checkout Steps
Tag Name: Ecommerce- Checkout
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Checkout Initiated
Event Label: {{Checkout_step}} Note: Here, I am using a variable that contains the checkout step name, like Shipping Address and Payment Method.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features :True: Use Data Layer
Triggering:
Trigger Name: Checkout Initiated
Trigger Type: Custom Event
Event name: checkout
This trigger will fire when the custom event equals ‘checkout’. Your final tag may look like the one below:
Tag for Measuring Purchase Event/ Transaction
Tag Name: Ecommerce- purchase
Tag Type: Universal Analytics
Track Type: Event
Event Category: eCommerce
Event Action: Purchased Product
Event Label: {{Purchase ID}} Note: Here, I am using a variable that contains the checkout step name like Shipping Address and Payment Method.
Event Value: {{Product Revenue}} Note: I am passing the purchase amount as product revenue in Event value.
Google Analytics Settings: <enter your property ID here>
Enable Enhanced Ecommerce Features:True: Use Data Layer
Triggering:
Trigger Name: ecommerce purchase event
Trigger Type: Custom Event
Event name: purchase
This trigger will fire when the custom event equals ‘purchase’. Your final tag may look like the one below:
#6.2 Click the ‘save’ button to create your new tag.
#6.3 Preview and debug your new tag, create a new container version and then publish the new container.
#6.4 Ensure that you are getting all of the ecommerce data in your GA report and that the data is accurate.
Once you deploy these tags, you will see enhanced ecommerce reports in your Google Analytics console under the ‘Conversions’ tab.
You can see multiple options available in reports, such as shopping behavior, checkout behavior, product performance, etc., which give you great details on all the ecommerce events happening on your website.
Frequently Asked Questions About Implementing Ecommerce Tracking via Google Tag Manager
What is ecommerce tracking?
Ecommerce tracking is a feature of Google Analytics through which you can track ecommerce data (like sales amount, number of orders, billing location, average order value, etc.) of a website/mobile app in Google Analytics.
Why do you need ecommerce tracking?
If you run/manage an online store/app, you can’t just depend upon the analytics reports provided by your shopping cart. You need Google Analytics Ecommerce tracking set up for your website. Only by using Google Analytics ecommerce tracking can you correlate sales data with website usage data like sessions, bounce rate, traffic source/medium, landing pages, etc.
This correlation analysis is required to understand the performance of your website landing pages and marketing campaigns. Otherwise, you may never know which landing pages and campaigns are driving sales and which are not.
How do I integrate my shopping cart with Google Tag Manager
This involves adding a ‘GTM container code’ on each page of your ecommerce website.
If you are using a custom shopping cart, ask your developer to add the GTM container code, immediately after the opening body tag <body>, on all website pages.
If you are using a third-party shopping cart like Shopify, you may need to refer to their help documentation or ask customer support about “where exactly to add the GTM container code?”. You would likely need to edit some template files and add your GTM code.
How do I enable enhanced ecommerce reporting in GA?
Google Analytics will report ecommerce data in your reporting view only when the ecommerce tracking has been turned on at the view level.
To enable enhanced ecommerce reporting, login to your Google Analytics account and then navigate to the ‘Admin’ section of your view: Click on the ‘Ecommerce settings’ link (under the ‘view’ column): then switch the toggle button to ‘ON’ (under ‘Enable Ecommerce Status’) and then switch the toggle button to ‘ON’ (under ‘Enable Enhanced Ecommerce Reporting’):
"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."
Here’s what we’re going to cover in this training…
#1 Why digital analytics is the key to online business success.
#2 The number 1 reason why most marketers are not able to scale their advertising and maximize sales.
#3 Why Google and Facebook ads don’t work for most businesses & how to make them work.
#4 Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.
#5 The number 1 reason why conversion optimization is not working for your business.
#6 How to advertise on any marketing platform for FREE with an unlimited budget.
#7 How to learn and master digital analytics and conversion optimization in record time.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.
About the Author
Himanshu Sharma
Founder, OptimizeSmart.com
Over 15 years of experience in digital analytics and marketing
Author of four best-selling books on digital analytics and conversion optimization
Nominated for Digital Analytics Association Awards for Excellence
Runs one of the most popular blogs in the world on digital analytics
Consultant to countless small and big businesses over the decade
Get My Step-By-Step Blueprint For Finding The Best KPIs (32 pages ebook)
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.