Bucketing Visitors into an Experiment and Variation Programmatically

THIS ARTICLE WILL HELP YOU:

Why would I do this?

This article is generally meant for customers that want to handle the bucketing of visitors themselves, if they have made randomization with another tool.

Sometimes you might want to decide which visitors see which variation of an experiment based on some custom internal logic. Be sure the population gets split in a random fashion as otherwise results might be biased. Example, if you show variation A to only visitors that are new to the site and variation B to only visitors that have at least 5 browsing sessions but did not buy yet, it's probably more likely that B would get a higher conversion rate and eventually win.

How to bucket the visitor a specific experiment-variation pair?

To do that, just trigger the following javascript code:


window._conv_q = window._conv_q || [];
window._conv_q.push(['assignVariation',"experiment_id","variation_id"]);

Replace the experiment_id and variation_id with the ids of your experiment and variation respectively. Make sure the above code is fired after the main tracking snippet. When the main snippet runs, the Locations targeting rules will be evaluated and if matched, the user will be assigned on the variation when the polling occurs (experiment conditions tested) or the experiment is manually triggered. Because the polling already would have occurred when this code has been triggered, then it would have to be triggered manually, or on the next page load automatically.

The polling sequence which tests all experiment conditions is run like this:


window._conv_q = _conv_q || [];
_conv_q.push({what: 'run'})

To manually trigger the specific experiment the code is:


window._conv_q = _conv_q || [];
_conv_q.push(["executeExperiment","experiment_id"]);

So the whole code might look like this in the end just manually triggering the experiment:


// This is to match the JS Condition on the Locations
experimentrun = 1;
window._conv_q = _conv_q || [];
_conv_q.push(['assignVariation',"100122263","1001175348"]);
// This only if you want to execute the experiment on the same page.
_conv_q.push(["executeExperiment","100122263"]);
 

Tips

You can find out how to determine your experiment and variation id by reading this article.