How to Set Up E-commerce Tracking in Classic Google Analytics
Wait a moment! Why are you using an outdated version of Google Analytics?
Classic is the outdated version of Google Analytics. Your business is missing out on advanced features, like cross-device tracking and much more.
This guide is for Classic Google Analytics. We’ve also written a guide for setting up e-commerce tracking for Universal Analytics.
If you’re considering upgrading to Universal Analytics (which you should be), check out our migration guide for Universal Analytics to upgrade to the latest tracking code.
Setting up e-commerce tracking for Google Analytics is relatively easy, although one little mistake can be enough to skew the data and provide erroneous reporting.
In this blog post, the latest in our e-commerce series, we talk you through the step-by-step process of setting up e-commerce tracking within Google Analytics.
What is e-commerce tracking?
E-commerce tracking is what allows you to measure the number of transactions and the amount of revenue generated by your website.
The e-commerce tracking for Google Analytics involves a four step process:
- Creating a transaction object
- Creating an item object and adding it to the transaction object
- Adding currency to the transaction
- Submitting the transaction to Google Analytics
How to create a transaction object
The first part of the process is creating the transaction object. This will contain grouped information for a single transaction, such as the total amount paid for a transaction. This will only appear once on the confirmation page. The following fields need to be added as part of the transaction object:
- Transaction ID – required field. This should be the same as the transaction ID given to the user when making the transaction
- Affiliation or store name – optional field. This can be used for a partner or store affiliation
- Total – required field. This is the total amount paid for a transaction. The total amount can be defined as including or excluding tax and delivery, depending on what is defined as the “total”. Whether there is an inclusion or exclusion of tax and delivery, there has to be a consistency on all transactions and this data must be numeric
- Tax – optional field. The total amount of tax paid tax when processing the transaction. Must be numeric
- Shipping – optional field. The total amount paid for delivery when processing the transaction. Must be numeric
- City – optional field. The user's billing city for the transaction
- State or county – optional field. The user's billing state or county for the transaction
- Country – optional field. The user's billing country for the transaction
Below is an example of how a transaction object would be added to the confirmation page:
How to add item objects to the transaction
The second part of the process is the “item”. This will contain information about individual items in a transaction. The amount of item objects to include on the confirmation page is dependent on how many different items are purchased during a transaction, but not the quantity of those individual items. The following fields need to be added as part of the item object:
- Transaction ID – required field. This must be exactly the same as the transaction ID in the transaction object
- SKU – required field. SKU stands for “stock keeping unit” and is a unique code for an item. Typically, this will be a product number or part number
- Item name – required field. This is the name given to an item
- Category – optional field. This is the name of the category that an item falls into
- Unit price – required field. This is the individual price for an item. It can be inclusive or exclusive of tax, but must be consistent on all transactions. Must be numeric
- Quantity – required field. The quantity of this item purchased in the transaction. Must be numeric
Below is an example of how to add the item object to the confirmation page:
How to add currency to the transaction
The default currency for transactions should be set in the properties section within a Google Analytics account. If transactions can be taken with more than one currency, the currency can be added as part of the e-commerce tracking.
Below is an example of how to specify a transaction in US dollars. This must be called before the transaction is sent to Google Analytics.
How to submit the transaction to Google Analytics
The final part of the process is to send the transaction data to Google Analytics. Below is an example of how to send the transaction data to Google Analytics:
It must be noted that the "_trackTrans" command must only be added once per transaction. The only exception to this is when implementing e-commerce data for roll up profiles: the "_trackTrans" can be fired once for each roll up profile.
Example of how to integrate e-commerce tracking with standard page view tracking
It is important that the standard page view tracking is included on the page that has the ecommerce tracking. The ecommerce tracking must appear after all the properties in Google Analytics (such as the ID of the Google Analytics account) have been added. It doesn't matter whether the transaction is sent to Google Analytics before the page view.
Below is a complete example of how to integrate ecommerce tracking with standard page view tracking:
How to test e-commerce tracking
The best way of testing e-commerce tracking is to use a HTTP traffic tool, such as Fiddler, Firebug or Google Developer Tools. When tracking is sent to Google Analytics, it will request a 1x1 pixel image from Google Analytics’ servers onto the page. The query string of the image URL will contain details such as the ID of the Google Analytics account. If e-commerce tracking is being sent to Google Analytics, the query string will contain details about the transaction.
The query string parameter to watch out for is "utmt". For e-commerce tracking, this should be set to "tran" if a transaction object is sent to Google Analytics. If an item object is sent to Google Analytics, the "utmt" query string parameter should be set to "item". Every item object that is sent to Google Analytics will be requested from an individual 1x1 pixel image.
Want to know more about e-commerce or tracking in Google Analytics? Contact us and one of our team will be happy to help.
Alternatively, read another of our related blog posts: