We all know that tracking business outcomes, or conversions, is absolutely critical. If you sell a product that means tracking transactions. Let’s walk through tracking ecommerce transactions with Universal Analytics.
How Ecommerce Tracking Works
In general, Universal Analytics ecommerce tracking functions the same way as the standard Google Analytics ecommerce tracking. Google Analaytics collects the transaction data using a special JavaScript tag that you need to place on your thank you page.
The hard part of tracking transactions is you need to insert the transaction details into a special ecommerce tag. That means you need to add some server side code to properly format the data.
The big difference between the current Google Analytics ecommerce tracking code and the Universal Analytics ecommerce tracking code is the format of the transaction data on your thank you page.
Step by Step Instructions
First, unlike the original emcommerce tracking code, you need to add an extra line of JavaScript to your thank you page. This code will load a special ecommerce tracking library to your thankyou page. This library contains all the code necessary to track a transaction.
ga('require', 'ecommerce', 'ecommerce.js');
For all you nerds, the reason that the ecommerce code is in a separate file is to reduce the overall size of the analytics.js
file. This makes your website load faster and improves the overall experience for your visitors.
The above code is in ADDITION to the standard page tag that you need to add to every page on your site.
Next, you need to add the transaction details to your thankyou page. Remember you need to create server side code that formats the transaction in a special way:
ga('ecommerce:addTransaction', {
id: '98765', // Transaction ID - this is normally generated by your system.
affiliation: 'Sugarbush Mt.', // Affiliation or store name
revenue: '89.00', // Grand Total
shipping: '0' , // Shipping cost
tax: '5.99' }); // Tax.
ga('ecommerce:addItem', {
id: '98765', // Transaction ID.
sku: 'LTAFD', // SKU/code.
name: 'One Day Adult Lift Ticket', // Product name.
category: 'Lift Tickets', // Category or variation.
price: '89.00', // Unit price.
quantity: '1'}); // Quantity.
ga('ecommerce:send');
There are three parts to the ecommerce tracking code.
The first section in the transaction data. This is summary information about the total transaction.
The second section contains information about each item in the transaction. In the code above there is only one item, it has SKU LTAFD
. If the customer purchased multiple items then there would be multiple item sections in the code. There needs to be one item section for each specific item purchased.
The final part of the code is the send line. This single line of code actually sends the data off to Google Analytics.
For all the nerds, the data is sent by an image request back to the Google Analytics servers.
Ok, let’s clearly define what each piece of data actually means.Here’s a short description of each part of the transaction data.
- ID: This is the transaction ID. It’s normally generated by your system. It should be unique for each transaction.
- Affiliation: In reality this is an open field that you can use to store any piece of data. This field is supposed to store any affiliate information, or store name. But you can basically use it for anything. I’ve seen people use it to store the name of a coupon.
- Revenue: An important metric for any ecommerce business. This specifies he total revenue associated with the transaction. This value should include any shipping and tax costs.
- Shipping: Any shipping costs associated with the transaction.
- Tax: Any tax associated with the transaction.
Now let’s look at the data associated with each individual item in the transaction.
- ID: This is the same id used in the transaction section. Google Analytics uses it to link the items in the transaction to the actual transaction.
- sku: Stock-keeping-unit. From the all-knowing Wikepedia: “SKU can also refer to a unique identifier or code that refers to the items or products they have available for sale. Each SKU is attached to an item, variant, product line, bundle, service, fee, or attachment. SKUs are often used to refer to different versions of the same product.”
- Name: A human-readable name for this product. This will be visible in many of the product reports.
- Category: The category that this product belongs to. Google Analytics can only assoicate one category to each product.
- Price: The price of an individual unit of this particular item.
- Quantity: The quantity that the customer purchased in this transaction.
Ecommerce Tracking Example
Ok, that’s a lot of techno-talk. Let’s look at a real-life example. Suppose I own a a bag company and someone completed the following transaction:
Transaction Details:
Transaction ID: a23nm45ys23
Total: $175.00
Tax: $0.00
Shipping: $25.00
Items Purchased in the transaction:
12345: one, Black 17″ Rollerbag, $100.00, SKU = RB17, Category = Luggage
45678: one, Black 15″ Rollerbag, $75.00, SKU = RB15, Category = Luggage
Here’s how I, as the business, would need to format the data in the thank-you page:
Notice how there are two sections for addItem
? That’s because there were two items in the transaction. Remember, you need an addItem
for each item that the customer purchased.
Don’t Forget Tag Management
If you want to future-proff your implementation, you might want consider adding your ecommerce data to a Data Layer. A data layer is data about your visitor and visit stored in a standardized way. By placing your data in a data layer you can switch between tracking technologies easily.
To track transactions using Google Tag Manager make sure the transaction data is added to the GTM Data Layer.
Creating an Ecommerce Tracking Plan
Implementing ecommerce tracking code is a critical measurement step for any ecommerce business. But it’s only one part of the tracking story. You need to consider collecting other information, like the number of customers vs. number of browsers using your site. You need to have a bigger measurement plan.
Check out some ideas for customizing Google Analytics to better measure your ecommerce business.
Thanks Justin,
and of course to implement _setCurrency, you’d need to add:
ga(‘set’, ‘currencyCode’, ‘EUR’); // set in global call or at transaction or item level
do note that, at present time, there seems to be no support for _setCurrency when using a transaction call via GTM
Is your example supposed to have a “ga(‘require’, ‘ecommerce’, ‘ecommerce.js’);” in it?
@Pierre: DOH! Thanks.
Hello Justin Cutroni,
Once again thank you for such a great post, after searching lot on the net I found best solution on your blog and implemented it.
Thanks Justin,
Amazing stuff like always. I am regular reader of your blogs. But posting comments first time.
I am eagerly waiting new innovations in Analytics, But irritated with increasing (Not Provided) in Google Analytics. Now I have tricks to remove 00:00:00 in single page visits with event tracking but I hope Google Analytics will surely do it its own as now Real Time Data is calculated. What are your views?
Justin, in one of your post “Integrating Google Analytics with a CRM ” you show how ga cookies data can be extracted and stored in the CRM system. Will this be possible in Universal analytics, where cookies are not used?
Thank you
Josef
@Josef: Great question. No. You will not be able to extract data from the Universal Analytics cookies. The reason is that UA will only use one cookie and it doesn’t hold any of the data I discuss in this post.
Thanks for the question.
Great Stuff! As an avid Google Analytics user, I never heard Universal Analytics. Will have to check it out!
Very informative information, Justin. I’ve scoured the web and your explanation of this was the clearest. Thanks for sharing.
There’s one aspect of this, I’m still not clear on. It appears that for transaction data, Universal collects five elements (ID, Affiliation, Revenue, Shipping, Tax). Let’s say that for each transaction, my company actually collects 15+ pieces of information. We do collect the 5 listed above, but they are labeled differently. For example, for us, “Revenue” is labeled “Total.”
How do I ensure the right fields in our data are properly captured and placed into the correct five buckets collected by Universal? It seems like there would need to be some code that indicates that “Total” = “Revenue” so that it would know to take the dollar amount in our “Total” field and place it in the “Revenue” field captured by Universal. Can you explain how this works?
@James: It’s really up to you to make sure that the right data ends up in the right location of the Analytics code. Your developers will need to create custom code that populates the Analytics code. There is no checking done by Google Analytics – it will accept the data. Make sure your development team reads all the documentation on the format for the ecommerce data. Hope that helps.