Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Analytics Tracking-Code zum Protokollieren von simplen A/B-Tests
<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
You can’t perform that action at this time.