Bucketing Visitors into an Experiment and Variation Programmatically

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?

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 Site Area 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:

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

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

Tips

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