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?

To do that, just trigger the following javascript code:

window._conv_q = window._conv_q || [];

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 || [];

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 || [];
// This only if you want to execute the experiment on the same page.
Need assistance? Start a conversation with our Support Team.

Reliably Convert More Site Visitors, Even If Everything Else is Changing in Your Business.

✓ No Credit Card  ✓ Easy Set-Up  ✓ Access All Features