Skip to content

Instantly share code, notes, and snippets.

@philbar
Created June 3, 2014 15:16
Show Gist options
  • Save philbar/cbda372be651d415f436 to your computer and use it in GitHub Desktop.
Save philbar/cbda372be651d415f436 to your computer and use it in GitHub Desktop.
<script>
function controlVariant() {
dataLayer.push({'event': 'google'});
return variantOne;
}
function testVariant() {
dataLayer.push({'event': 'adroll'});
return variantTwo;
}
var randomNumSample = 1073741824,
variantOne = "google", // Variation 1 name
variantTwo = "adroll", // Variation 2 name
variant = variantOne;
if(!{{Split Variation Cookie}} && randomNumSample) { // If cookie isn't set run code
if({{Random Number}} < randomNumSample) {
variant = testVariant(); // For 50 % of hits, fire Variation 2
}
else if({{Random Number}} >= randomNumSample) {
variant = controlVariant(); // For 50 % of hits, fire Variation 1
}
var d = new Date(); // Create cookie
d.setTime(d.getTime()+1000*60*60*24*730);
var expires = "expires="+d.toGMTString();
document.cookie = "splitVar="+variant+"; "+expires+"; path=/";
}
else if({{Split Variation Cookie}} == variantOne) { // If user has only seen Variation 1
variant = controlVariant();
}
else if({{Split Variation Cookie}} == variantTwo) { // If user has only seen Variation 2
variant = testVariant();
}
</script>
@putun
Copy link

putun commented Jan 13, 2017

Hi Phil,

I would like to understand your concept and logic about A/B testing for retargeting. Do you use your tag manager script for splitting retargeter audience collector pixels?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment