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
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
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:
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.
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.
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 ID: a23nm45ys23
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.