How to set up Ecommerce Tracking in Universal Analytics

If your business is selling products online, reporting product purchases using a web analytics tool such as Google Analytics (GA) is essential to understanding and measuring performance. Your business can understand the outcome of your marketing campaigns by linking them with purchases and subsequently tracking the return on investment (ROI).

If you can analyse your user behaviour and your marketing performance, you will be able to optimise the user experience and ultimately increase business revenue.

This post will walk you through:

How ecommerce tracking works in Universal Analytics

The different data you can get from ecommerce tracking

How to set up ecommerce tracking in Google Analytics

What code changes your website requires

How to format the ecommerce data

How to test and debug ecommerce tracking issues

Adding payment gateways to your referral exclusion list

How does ecommerce tracking work in Universal Analytics?

Ecommerce tracking in Universal Analytics (UA) requires extra code and implementation on top of the normal page view tracking.

What data can I get from ecommerce tracking?

With ecommerce tracking enabled in Google Analytics, you’ll be able to see:

Revenue from product sales

Average order value

Total transactions and product purchases

Number of days/sessions before a transaction occurred

Sales performance on particular dates

Ecommerce tracking can also include the product category to analyse product performance in groups. This all combines to give you lots of useful business data that you can segment by marketing channel and user behaviour.

“Where are ecommerce reports located?”

Ecommerce reports are located in the reporting view in the Conversions category of the main left navigation. If ecommerce is not enabled in your Google Analytics settings, this report will show an error message.

How to implement ecommerce tracking

Ecommerce tracking is an official plugin for Google Analytics that provides a method for measuring transactions and product performance.

Ecommerce is enabled in the Admin area of Google Analytics. Click ‘Ecommerce settings’ under the view for which you wish to enable ecommerce. Then, click the ‘Enable Ecommerce’ button to ‘ON’.

Step 2: Website code changes

On a standard ecommerce site, these code changes should be made to the confirmation page, which is displayed after a successful transaction has been made.

These code changes include:

Enabling the ecommerce plugin

Creating a transaction

Adding each product in the user’s transaction as an item

Sending the transaction to Google Analytics

Enabling the ecommerce plugin

The following code enables the ecommerce plugin:

ga('require', 'ecommerce');

Plugins should be enabled after the creation of the Google Analytics tracker but before any specific ecommerce functionality. A full code example is included at the end of this section of the post.

Creating a transaction

Key point: All transaction and product data should be populated using the server data. The ecommerce data should be dynamically added to the final page as JavaScript. Avoid ‘pulling’ the data from HTML elements after the confirmation page has been loaded.

Key point: Do not send any personally identifiable information (PII), such as the customer name or address, to Google Analytics. This is against Google Analytics’ terms and conditions and may result in your account being removed.

Sending the data to Google Analytics

Once the transaction and item code has populated, send the data to Google Analytics using the following command:

ga('ecommerce:send');

And that is everything required for a standard ecommerce set up.

Here is what the full JavaScript code looks like, alongside a Google Analytics page view:

How to test the ecommerce tracking code

Google Analytics sends data through HTTP requests so Google Developer Tools can be used to check these requests.

Hits for Universal Analytics start with the URL path ‘collect?...’. There should be a collect hit for each item and a hit for the transaction. The ‘t’ value in the query string parameters will provide the type of hit: transaction or item.

Common ecommerce tracking problems and solutions

Referral issues caused by payment providers like PayPal.

If you can see paypal.com or other payment providers in your referral report (Acquisition > All Traffic > Referrals), those transactions will no longer be attributed to the original traffic channel, e.g. organic or Facebook campaigns.

Fix this by adding them to the referral exclusion list in the Property settings:

Users refreshing confirmation pages can cause duplicate transactions.

Fix this by setting a flag in the database table. The flag should be set when the user first sees the confirmation page. The GA transaction code should be hidden when the flag is set to true, in order to prevent page refreshes causing duplicate transactions.

Internal traffic from development testing often causes inflated transaction revenue.

To fix this problem, ensure your internal IP addresses are filtered in Google Analytics. If you aren’t sure about the integrity of your Google Analytics setup, then contact our analytics team to arrange a health check.

Not escaping product names and categories can cause tracking problems for certain products.

Ensure the JavaScript syntax does not break for certain products by escaping special characters, like quotation marks, with a \’ backslash.