0131 560 1790 0131 560 1790

Installing Ecommerce Tracking for Your Website

So you’ve got an ecommerce website. Good for you. With a good business model, stylish design and the right kind of SEO and e-marketing I’m sure you’ll start to see the sales role in. No doubt you’ll already be using Google Analytics to track everything on your site from visitor trends to website goals. However, one of the most vital sections of Analytics specific to Ecommerce sites is Ecommerce Tracking.

Ecommerce Tracking provides a highly detailed breakdown of each and every transaction made on your site, breaking it down into an array of useful numbers such as: the total purchases, average order value and the per visit value of your site. In short, ecommerce tracking provides you with all the information you’ll need to monitor your sales, and tailor your SEO and marketing to take advantage of your site’s strengths and iron out its weaknesses. So how do we get started?

The Installation

The Easy Bit

If you already have Google Analytics setup then you’re well on your way to getting started with ecommerce tracking. At the Analytics end all you have to do is change one setting. When viewing the account in Analytics, access Analytics Settings and choose the Edit action to enter the Profile Settings. From here select ‘Edit’, (found to the top right of the Main Website Profile Information section). Simply ensure that the correct currency is displayed, and select the ‘Yes, an E-Commerce Site’ radio button.

That’s it from the Analytics end. The way ecommerce tracking works is that Analytics is always ready to receive the information. All you have done here is asked Analytics to display it to you when it is returned.

The Tricky Part

This part of the process is the difficult bit. Much like the initial installation of analytics, it requires you to put code into your site. However, in this case it’s not a simple case of copy and paste as the code you put in needs to be manipulated to pull in data for your site. Depending on whether you are using PHP, ASP or Coldfusion it has to be set to pull in variables passed through during transactions on your site.

It is highly recommended that one of the sites developers take care of this aspect as this requires a good understanding of website development to install. Attempting to do this without the appropriate knowledge and understanding could well do serious harm to your sites inner workings.

Asynchronous Syntax

<html>
<head>
<title>Receipt for your clothing purchase from Acme Clothing</title>
<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'1234',           // order ID - required
'Acme Clothing',  // affiliation or store name
'11.99',          // total - required
'1.29',           // tax
'5',              // shipping
'San Jose',       // city
'California',     // state or province
'USA'             // country
]);

// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push(['_addItem',
'1234',           // order ID - required
'DD44',           // SKU/code - required
'T-Shirt',        // product name
'Green Medium',   // category or variation
'11.99',          // unit price - required
'1'               // quantity - required
]);
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
</head>
<body>

Thank you for your order.  You will receive an email containing all your order details.

</body>
</html>

Above is a complete example of the ecommerce tracking code applied within the receipt page of a website. For your site, ensure that the code is applied within the confirmation page that immediately follows a purchase.

We are using the Asynchronous tracking code here as it is a more efficient version and can be run within the <head> section of the table. The asynchronous version is faster loading and reduces slowdown on your site, rendering the traditional in-body syntax practically obsolete.

Configuring the Tracking Script

The tracking script above is most easily understood when broken down into the three main methods involved:

_addTrans

This method is used to initialise a transaction object. This stores all of the information about a single transaction including common details such as the order ID, shipping costs and the shipping address. The order ID acts as the primary key that links the transaction to the items.

_addItem

This method is used to track each individual item that is in the users shopping cart. It includes the order ID, product name, unit price, etc.

_trackTrans

This method confirms that the purchase has been made, the data has been collected and that the transaction is finalised. It in effect closes the transaction and ends the running of the code.

Of course this code will have to be manipulated to cater for your ecommerce setup. The areas which will require change are the _addItem() and _trackTrans() sections. You will also have to add your UA number into the top of the code where indicated.

Much in the same way that you pass the variables for each product from the shopping cart to your orders database, you will have to pass the strings into these sections of the code.

For a PHP site:

_gaq.push(['_addTrans',
'1234',           // order ID - required
'Acme Clothing',  // affiliation or store name
'11.99',          // total - required

Could be replaced with:

_gaq.push(['_addTrans',
<?php echo"\"".$invoiceid."\"";?>,          // order ID - required
"Example.com",                    // affiliation or store name
<?php echo"\"".$totalamount."\"";?>,        // total - required

You can see in this example that the store name is a basic string and not a variable, as in this case this object will remain consistent for each transaction.

While you should attempt to fill each object with data only, some are completely essential with many optional extras. For _addItem() only the SKU, price and quantity are required, while for _addTrans() only the orderId and the total are essential.

Of course you should provide information wherever possible to ensure there is as much data being passed to Analytics as possible.

Start Getting Results

Once this is setup and applied to your Google Analytics account you will be able to start tracking each order and gather more sophisticated data on customer trends. By making use of this feature you can develop a more comprehensive understanding of your customers and develop your SEO, marketing and services to constantly improve your business model and bring greater success.

[youtube]http://www.youtube.com/watch?v=_lOlbtkTY2Y&feature=player_embedded[/youtube]



You may also be interested in:

  1. Google Release New Improved Analytics Tracking Code Want to place your analytics code higher up the page but don’t want it to interrupt other elements on your...
  2. Web Analytics TV #9 Review – Back to the Future Review of Google's latest analytics TV show. Learn how to track visits from pigs. ...
  3. How to tell if your ecommerce site is doing its job properly As any marketing expert will tell you, there is no such thing as a ‘good’ design, just a design which...
  4. 1 Defining Tip To Make Your Ecommerce Website a Success Making your website a success can be hard. Find out the most important factor in making your website number 1....
  5. We Love Web Analytics TV – Episode 14 Check out another top video from our favourite analytical gurus at Google. ...

You can follow any responses to this entry through the RSS 2.0 feed.