Skip to main content

Custom Assignments

Sometimes it may be necessary to override the automatic selection of a variant. For example, if you wish to have your variant chosen based on data from an API call. This can be accomplished using the context.customAssignment() method.

const chosenVariant = 1;

context.customAssignment("experiment_name", chosenVariant);

If you are running multiple experiments and need to choose different custom assignments for each one, you can do so using the customAssignments method.

const assignments = {
experiment_name: 1,
another_experiment_name: 0,
a_third_experiment_name: 2,
};

context.customAssignments(assignments);
info

These methods can be called before or after the context is ready.