See Google Website Optimizer (MVT) Tests in Google Analytics
So, you’re about to run a test in Google Website Optimizer and you have to track something crazy like revenue per visitor, ecommerce tracking, multiple goal points and so on… If you’re just running plain old GWO, you can’t track that – Sucks I know, but…
Custom Variables and Google Analytics Save the Day
I initially got this code from Cameron over at Analytics Market (but I’ve since tweaked it to improve error handling and to keep data within GA accurate). It’s been a life-saver for whenever I’ve been tracking micro conversions (click throughs, vistor engagement etc) and wanted to peek a little deeper into visitor behaviour on the site, right through to the macro conversion (i.e. purchase, sign up, application, transaction values, lead conversion in CRM etc).
Anyway, by using Custom Variables you’re able to insert the variation number from GWO into GA, like so:
All you need to do is throw in code like this within your Google Analytics code:
try {
if(utmx('combination') != undefined){
try {pageTracker._setCustomVar(1, "Test-1", "Variation-" + utmx('combination'), 2);
}
}catch(err){}
Otherwise, if you’re using the new asynchronous tracking, use this:
try {
if(utmx('combination') != undefined){
_gaq.push(['_setCustomVar', 1, 'Test-1', 'Variation-' + utmx('combination'), 1]);
}
}catch(err){}
Your Google Analytics code then should resemble:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
try {
if(utmx('combination') != undefined){
_gaq.push(['_setCustomVar', 1, 'Test-1', 'Variation-' + utmx('combination'), 1]);
}
}catch(err){}
_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);
})();
Importantly, note how setCustomVar is placed before trackPageview but after setAccount? This order is important to ensure tracking.
Deciphering the code:
‘
1‘ refers to the slot the variable sits in (GA currently allows you to use 5 slots – 1 through to 5)
‘"Test-1"‘ is the name of the variable – I suggest you use the name of your experiment here
‘"Variation-" + utmx('combination')‘ dynamically inserts the GWO variation number into GA
‘1‘ refers to the scope of the variable. I recommend using ’1′ if you’re only running a single experiment on the site, or ’3′ if you are running more than one experiment on the site.
I suggest reading more information on using custom variables over at Google’s documentation.
Analysing Test Data in Google Analytics
All you need to do now, is run some reports – I recommend setting up advanced segments as I have done in some examples above, or through creating custom reports.
To find out if the result is statistically valid or not, you should try my A/B/n split test significance calculator.
Track GWO A/B/n Experiments in GA
This also requires a different setup read another followup post of mine here on Tracking A/B Experiments in Google Analytics.



Thank you for this cool solution, it is exactly what I was looking for!
Just note: It is necessary to have GWO code at all pages – if not, it causes JavaScript error and GA tracking is not working.
Thanks Jirka… I haven’t updated this script in a long time, but I’ve just added a fix for it.
Try that and it should work on all pages without the GWO code.
Thanks, I already fixed it in the same way
According to my test it works flawlessly now.
Well done! Great minds think alike. :p