Google analytics ecommerce tracking – the best way to track your sales

Google analytics happens to be the best tool to track your websites traffic,sources and other data. But very little people know about their ecommerce tracking feature. Being an era of e-commerce, were all the people buy things online, this ecommerce tracking has got high relevance.

What is google analytics ecommerce tracking?

In a normal e-commerce website, a sale is recorded when a user buys a product (or a payment  transaction  is made with respect to the product) that is when the success response is obtained from the payment gateway. We can use google analytics to track this transaction and to integrate the sales to the google analytics account.  We can pass lots of parameters like, revenue,item name,item code,currency,category,quantity,shipping charges etc to Google analytics which will be recorded  in it.

Read - How to start an ecommerce website by yourself under 100$

How to set up ecommerce tracking for your website?

  1. You need to get into the profile of your website in google analytics, every website which you have added in GA should have a profile.
  2. Go to the admin section, click the admin button on top of your analytics account.
  3. Select the particular profile of your website which you are planning to track, and its profile settings.profle
  4. In the profile setting ,if you scroll down a little bit you  can see drop down which asks you whether your website is an eccomerce site? Select Yes an ecommerce site option from the drop down and apply it. By doing this you are telling GA that your website is an ecommerce website so that the ecommerce tracking feature should be enabled.
  5. Now if you go to your reporting and select the conversions tab (on the bottom left), and then select the ecommerce section, you can see the ecommerce tracking results.  This shows the amount of sales, quantity, total value of sales, detailed product wise performace, transactions, time etc. Or in short everything you need as  a tracking for an ecommerce website.

How to setup?

You need to paste the tracking codes given below on your success page after buying a product, or in the return url from the payment gateway. In short , it should be on a page where you can get the product details and a confirmation for the payment made.

You need to  load

You need to load this after you create your tracker object. "analytics.js" doest have this ecommerce tracking script, so you need to load this separately.

There are mainly two methods to achieve this tracking.

  1. addTransaction
  2. addItem

We can add the transaction data to the object using addTransaction method.

Using the addItem method we can pass the product details to ga object.

After loading data to the object, we need to pass these data to google analytics.

After sending the data to analytics, the object will get cleared for the new transaction, or you can clear it manually.

Putting it all together

If you check the above code, you can find that the ecommerce.js has been loaded just below the normal pageview tracking analytics  javascript.

Working example for Google analytics ecommerce tracking in PHP

First of all we port all the details of the transactions into one associative array, and the items purchased(may be more than one) into another associative array .

 

The below function converts the data to required javascript format to send over to the google analytics server.

Function to return the JavaScript format of an ItemData object.

After that we runs the script for the ecommerce tracking and ports the php variables to js format to send over to  the google analytics server, and your each and every sale will be recorded in analytics.

The above given code loops through all the transaction details and product item data, converts them into required js format and sends to  Google analytics. Check the below screenshot of google analytics ecommerce tracking. It should look like this if everything goes good.

google analytics ecommerce tracking

 

Check for more reference
Hope you enjoyed this tutorial, we love comments, please post your opinions and suggestions as comments 🙂 .

Author: Linjo Joson

Myself Linjo Joson, here in dollarfry , I write articles about creating and optimizing websites as well as making money from your online business. I am PHP/WordPress developer by proffession.I love web analytics and driving traffic to them(doing this for 9 years). You can find me on Google+