Test object parameter reference in Mojito JS Delivery
The test object contains everything an experiment needs to run, including the trigger, tracking information and recipe code (or variants). When you pass all this information into the Mojito.addTest()
function, Mojito will execute all the logic in your experiment based on its order of execution.
Example test objects in JS
& YAML
formats
JavaScript
Mojito.addTest({
"id": "w12",
"name": "Example test",
"divertTo": "1",
"sampleRate": 1,
"state": "live",
"gaExperimentId": "dsdy2h872g7d32h782n2",
"trigger": function (testObject) {
if (document.location.pathname === "/") {
// Activate the test at DOM Content Loaded
Mojito.utils.domReady(testObject.activate);
}
},
"recipes": {
"0": {
"name": "control"
},
"1": {
"name": "treatment",
"js": function(testObject) {
alert("You're in an experiment...");
},
"css": "body{display:none;}"
}
}
});
YAML
id: w12
name: Example test
divertTo: "1"
sampleRate: 1
state: live
gaExperimentId: dsdy2h872g7d32h782n2
trigger: trigger.js
recipes:
"0":
name: control
"1":
name: treatment
js: 1.js
css: 1.css
YAML trigger.js
function trigger(testObject) {
if (document.location.pathname === "/") {
// Activate the test at DOM Content Loaded
Mojito.utils.domReady(testObject.activate);
}
}
YAML 1.js
function(testObject) {
alert("You're in an experiment...");
}
YAML 1.css
body {
display:none;
}
Test object: Root level
Parameter | Description |
---|---|
css Type: string Optional | Shared CSS for the test object that is applied to all recipes. JS format : Expects a JS string of CSS styles. YAML format : Expects a relative path to a CSS file. |
divertTo Type: string Optional | Enable divert mode to send all eligible traffic into a particular recipe's key. |
id Type: string Required | A canonical test object ID by which subjects' assignments are recorded against. |
js Type: function/object Optional | Shared JS function or object for the test object that is applied to all recipes. JS format : Expects a valid JavaScript function on this key. YAML format : Expects a relative path to a JS file with that function/object. |
name Type: string Required | The name of the test object that's useful in tracking. |
recipes Type: object Required | An object containing the definition of available recipes. See object definition |
sampleRate Type: number Required | The percentage of traffic to assign into the experiment between 0 and 1 (where 1 is 100%) |
state Type: string Required | A test object's state. Can be either: live - in the container, accepting traffic into the experiment staging - built into the container but not accepting traffic without a preview URL inactive - not parsed or built into the container |
trigger Type: function Required | A JavaScript function executed as soon as the test object is loaded and can be used to conditionally activate an experiment. JS format : Expects a valid JavaScript function on this key. YAML format : Expects a relative path to a JS file with that function. |
Recipes object
Parameter | Description |
---|---|
{"{"}{"{"}recipeId{"}"}{"}"} Type: string Required | The canonical key that references a test object within the cookies and preview URLs. See object definition. E.g. A recipeID of a would be accesible through a preview URL like: https://www.example.com/?mojito_w12=a |
Recipe objects sub-level
Parameter | Description |
---|---|
css Type: string Optional | CSS that is applied as soon as the subject is bucketed. JS format : Expects a JS string of CSS styles. YAML format : Expects a relative path to a CSS file. |
js Type: function Optional | A JavaScript function that runs as soon as a subject is assigned into the test. JS format : Expects a valid JavaScript function on this key. YAML format : Expects a relative path to a JS file with that function. |
name Type: string Required | The name of the recipe used in tracking & reporting. |
sampleRate Type: number Optional | Allows users to set the proportion of traffic allocated to each recipe. This property expects a value between 0 and 1 and requires all recipes' provided sample rates to add up to 1 . |