Split testing (or A/B testing) with Clicky
Quick script for tracking split tests (or A/B tests) using Clicky analytics. This must go before Clicky is loaded.
// set the colours available
var colours = Array('red', 'yellow', 'blue');
// choose one at random
var colour = colours[Math.floor(Math.random()*colours.length)];
// create the var
var clicky_custom = {};
// test for a cookie setting the colour already
if ( !$.cookie('buttoncolour') ) {
// no cookie so set one
$.cookie("buttoncolour", colour, { expires : 7 });
// add the relevant class to the button
$('input#purchase').addClass(colour);
// tell clicky what to record
clicky_custom.split = {
name: 'Button colour',
version: colour
};
} else {
// cookie is set so get the value and use it
$('input#purchase').addClass($.cookie('buttoncolour'));
clicky_custom.split = {
name: 'Button colour',
version: $.cookie('buttoncolour')
};
}