Created
June 11, 2012 19:23
-
-
Save sergejmueller/2912115 to your computer and use it in GitHub Desktop.
Google Analytics Tracking-Code zum Protokollieren von simplen A/B-Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-XXXXX-Y']); | |
_gaq.push(['_trackPageview']); | |
_gaq.push( | |
function() { | |
var tracker = _gat._getTrackerByName(), | |
group = tracker._getVisitorCustomVar(1), | |
random = Math.random(); | |
if ( typeof(group) === 'undefined' ) { | |
if ( random < 0.25 ) { | |
group = 'A'; | |
} else if ( random < 0.50 ) { | |
group = 'B'; | |
} else if ( random < 0.75 ) { | |
group = 'C'; | |
} else { | |
group = 'D'; | |
} | |
_gaq.push( | |
['_setCustomVar', 1, 'A/B Test', group, 1] | |
); | |
} | |
switch(group) { | |
case 'A': | |
/* Handlung für Version A */ | |
break; | |
case 'B': | |
/* Handlung für Version B */ | |
break; | |
case 'C': | |
/* Handlung für Version C */ | |
break; | |
default: | |
/* Handlung für Version D */ | |
break; | |
} | |
} | |
); | |
(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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment