Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
With this script you are good to go for client-site A/B/n testing with Content Experiments. Add ?var=1 to preview the variation of the A/B test.
<script src="//"></script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(;
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
var varID = getParameterByName('var');
if(! varID){ var chosenVariation = cxApi.chooseVariation(); }
else { var chosenVariation = varID; };
var pageVariations = [
ga("send","event","AB-test","GTM-001 Name of the test","Control",{nonInteraction:1});
ga("send","event","AB-test","GTM-001 Name of the test","Variation 1",{nonInteraction:1});

This comment has been minimized.

Copy link
Owner Author

simonvreeman commented Jan 26, 2015

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.