How to Track Ecommerce Transactions with Google AnalyticsBy Craig Buckler
Why Track Transactions in Google Analytics?
Your ecommerce system can provide detailed transaction statistics, but you can’t necessarily relate them to page views or other factors. For example, was an increase in sales caused by SEO improvements, a successful email campaign, advertising or seasonal variations?
Recording all transactions in Google Analytics provides a richer set of customer and product reports. With this information, you can assess the success of campaigns and concentrate on those which lead to increased ROI.
Ecommerce Tracking Basics
In most cases, a shop visitor will add items to a cart, proceed to the checkout, perhaps register, pay an amount, and be shown a receipt page. The full details of the transaction must be passed to Google Analytics at the “receipt” page stage.
Enable Ecommerce Tracking
By default, Google Analytics disables ecommerce reports, so you must choose “Yes, an E-commerce Site” on the edit profile screen (click Edit at the top-right of the Profile Settings page).
There are five distinct parts to the ecommerce tracking code.
1. Set the account and track the page
The standard Google Analytics tracking code must be implemented, i.e.
var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-XXXXX-X']); // your GA ID _gaq.push(['_trackPageview']); // track the page view
2. Add transaction details
The next code block provides information about the transaction. It must include the following data in this order:
- the order ID (required)
- the store or affiliate name (required, but can be an empty string)
- the total amount (required)
- the tax amount
- the shipping charge
- the buyer’s city
- the buyer’s state, county or province
- the buyer’s country
_gaq.push(['_addTrans', '1234', // order ID 'SitePoint', // store '19.99', // total '1.50', // tax '3.00', // shipping 'Chicago', // city 'Illinois', // state 'USA' // country ]);
3. Add individual products
A code block is required for all products purchased within the transaction. The data is required in the following order:
- the order ID (must be the same as the transaction)
- the product code or SKU
- the product name
- the category or a variation, e.g. large size
- the unit price
- the quantity
_gaq.push(['_addItem', '1234', // order ID 'css123', // SKU/code 'CSS Live', // product name 'Online Course', // category or variation '9.99', // unit price '1' // quantity ]);
4. Submit the transaction
The last instruction submits all transaction data to Google Analytics:
5. Load the Google Analytics script
Finally, we must remember to load the Analytics script. The asynchronous syntax is recommended:
Putting It All Together
Your final ‘receipt’ page will look something like this:
Within a few hours, you’ll be able to view buying statistics in the Ecommerce section of the Google Analytics panel. You will also find further ‘Ecommerce’ tabs on other reports.
Are you tracking ecommerce transactions in Google Analytics? Have you found it useful?
If you want to read more from Craig, subscribe to our weekly tech geek newsletter, Tech Times.