Running Multiple Concurrent Experiments

The JavaScript code below allows you to weight traffic allocation to ensure that multiple concurrent experiments can run without starving each other of traffic.

(function(exps, weights) {

function weightedRandomSelection(weights) {
var totalWeight = 0;
for (var i = 0; i < weights.length; i += 1) {
totalWeight += weights[i];
}
var random = Math.random() * totalWeight;
for (i = 0; i < weights.length; i += 1) {
random -= weights[i];
if (random < 0) {
return i;
}
}
return 0;
}

var exp = exps[weightedRandomSelection(weights)];
var cookieName = "exp_ascend";
var cookieValue = `${exp}`;
document.cookie = cookieName + "=" + cookieValue;

})(['exp1', 'exp2', 'exp3'], [5, 10, 85]);
 
The primary example of this is an experiment on the homepage taking all the available users, so an experiment on the PDP has no users available to enter into the experiment.
 
Requirements:
 
1) The code above must be run before the Ascend snippet
2) It should be placed on every page that has the Ascend snippet
3) The example call of
```
(['exp1', 'exp2', 'exp3'], [5, 10, 85])
```
 
Means:
'exp1' will receive 5% of the users
'exp2' will receive 10% of the users
'exp3' will receive 85% of the users
 
Note that the example code will ALWAYS select an experiment for a user -- if you want to test on only a subset of users, then traffic throttling, or other filters should still be used
 
4) In the homepage and pdp experiment example, you would configure something like this:
```
(['homepage', 'pdp'], [5, 95])
```
This gives homepage only 5% of the users, as it will see much higher traffic
5) This code only returns the experiment the user should be allocated to - to make use of this information in Ascend, set a cookie with returned experiment value
6) Create audience filters looking for each cookie value
Screen_Shot_2018-09-26_at_11.25.38_AM.png
7) Apply the audience filter to the appropriate experiment
Screen_Shot_2018-09-26_at_11.33.04_AM.png

 
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk