Rune Grønkjærs Blog
Abonnér på mit feed

Google Analytics e-commerce

Do you know who your paying customers on your site is? And do you have an overview of what and how much they buy? To know this, you need to know how your customers move on your website. Google Analytics provides, as standard lots of opportunities to explore your users’ behavior, but with a few additions to Google analytics and your shop, you will have even more knowledge.

In this blog post I will show how you can use the Google Analytics E-commerce function. It’s not that hard, and gives you lots of new statistic data.

What can I use Google Analytics e-commerce for?

Google Analytics e-commerce will be used to track the trade that occurres on your website. You can see how well your site converts users for sale and how much they buy. Where it might be really interesting is that e-commerce statistics also become intertwined with the usual statistics on the website. In this blog post I will not go through all the possibilities, but write how you’re going to collect the data to have them.

Tea Commerce and Google Analytics e-commerce

To collect statistics on your users’ purchases on your shop, we have set up two things. Firstly, the e-commerce part of Google Analytics needs to be activated. The second thing will be to insert a piece of code in Google’s tracking JavaScript in your e-commerce website.

Setting up Google Analytics e-commerce

To turn on Google Analytics e-commerce you need to go to the settings for your websites Google Analytics. Google explains it pretty well on this page , but below I have just repeated what should be done.

How do I track e-commerce transactions?

  1. Sign in to your account.
  2. Click Edit next to the profile you’d like to enable.
  3. On the Profile Settings page, click Edit next to Main Website Profile Information.
  4. Change the E-Commerce Website radio button from No to Yes.
Once you’ve done this a new menu item called “E-Commerce” will be available underneath your website’s other statistics in Google Analytics. There will also be Ecommerce tabs in different parts of the normal statistics. Of course there are no data yet. They will first be collected when you’ve done the following.

Tracking your e-commerce orders

Now we need to insert some JavaScript into the normal tracking script from google. The starting point should hopefully be something like what you see below and it will probably be in the header of the website. I have inserted a comment where our tracking code to the e-commerce will be placed.

Google analytics standard tracking code

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3982655-28']);
_gaq.push(['_trackPageview']);

/* INSERT E-COMMERCE TRACKING HERE */

(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);
})();


Now we need to generate the JavaScript that will provide information about the order. We must ensure that it only appears when the user has completed his order and we must send various information about the order and its order lines. Google has written great deal of documentation on the subject, of course, and you can read it here.

Generating the Tea Commerce order data with XSLT

I made a piece of code that can be used in all Tea Commerce webshops. Just be sure to check my aliases against your own. Create a new xslt file and macro called “googleEcommcereTracking.xslt” and paste the following in the template tag. Remember that the right ID on the confirmation page, which is in the first “if” condition.

Tea Commerce Google Analytics e-commerce tracking code



  
  
  
  
    
    _gaq.push(['_addTrans',
      '',           // order ID - required
      'runeswebshop.com',  // affiliation or store name
      '', // total - required
      '',             // tax
      '',// shipping
      '',        // city
      '',                                                        // state or province
      ''      // 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',
      '',               // order ID - required
      '', // SKU/code - required
      '',   // product name
      '',   // category or variation
      '',     // unit price - required
      ''                 // quantity - required
    ]);
    
    _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
  



Now we just have to insert our new macro in the Google Analytics tracking code in the websites header. The tracking code will now look as follows.

Tracking Code with e-commerce tracking macro

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3982655-28']);
_gaq.push(['_trackPageview']);



(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);
})();


That should do it. When we now run a test order and reaches the order confirmation, the google tracking code should look like the below. On all other pages, the tracking code will look just as usual. Now, your webshop will start collecting data and you will not miss out on some great statistics.

Google Analytics tracking code on the order confirmation page

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3982655-15']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);


_gaq.push(['_addTrans',
      '56',                 // order ID - required
      'runeswebshop.com',   // affiliation or store name
      '10400.0000000000',   // total - required
      '2600.00000000000000',// tax
      '0.00000',            // shipping
      'Herning',            // city
      '',                   // state or province
      '1'                   // 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',
      '56',                                 // order ID - required
      '8040000065',                         // SKU/code - required
      'Vedligeholdelsesfrit havemøbelsæt',  // product name
      'Havemøbler',                         // category or variation
      '8000.0',                             // unit price - required
      '1'                                   // quantity - required
    ]);


// 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',
      '56',           // order ID - required
      '1130000001',   // SKU/code - required
      'RENSDYRSKIND', // product name
      'Interiør',     // category or variation
      '1200.0',       // unit price - required
      '2'             // 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);
})();

Tea Commerce links

This post was written in Analytics, e-commerce, Tea Commerce, Umbraco, xslt. Ad permalink to favorites. Follow all comments with RSS feed for this posts. Drop a comment or a trackback: Trackback URL. | Læs denne side på dansk dansk version

Drop a comment

Your email is never published nor shared. Required fields are marked *

*
*

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Dansk version