Experiment APIs

Miso's experiment APIs let you do the A/B testing of your current result with Miso.

Start an experiment in Dojo.

Login to the dojo platform. Create an experiment event for you.

Start running A/B testing in your environment.

Implement A/B testing code.

Here's an example in NodeJS. You can also use any programming language of you choice.

const axios = require('axios');

async function get_user_experiment_info(api_key, experiment_id, user_id) {
    data = {"user_id": user_id}
    endpoint = `https://api.askmiso.com/v1/experiments/${experiment_id}/events?api_key=${api_key}`
    return await axios.post(endpoint, data)
}

const api_key = '<YOUR_SECRET_API_KEY>'
const experiment_id = "<EXPERIMENT_ID | EXPERIMENT_SLUG_NAME>"
let user_id = 'user_1234'  // use to evaluate a treatment for

const user_experiment_info = get_user_experiment_info(api_key, experiment_id, user_id)
user_experiment_info.then((response) => {
    let variant = response.data['variant']
    if (variant['name'] == "treatment") {
        // insert code here to show "treatment" variant
    } else if (variant['name'] == "control") {
        // insert code here to show "control" variant
    } else {
        // unexpected variant name. raise error
        throw new Error(`Unexpected variant name ${variant["name"]}`)
    }
})

If you implement A/B testing code in FrontEnd, like JavaScript, and are also worried about exploding the secret api_key. You can choose to use anonymous_id with the public_api_key for this API. Here's an example.

const apiKey = '<YOUR_PUBLIC_API_KEY>';
const experimentId = '<EXPERIMENT_ID | EXPERIMENT_SLUG_NAME>';
const anonymous_id = 'user_1234';  // use to evaluate a treatment for

function getUserExperimentInfo(apiKey, experimentId, anonymous_id) {
  const data = {
    user_id: anonymous_id
  };
  const url = `https://api.askmiso.com/v1/experiments/${experimentId}/events?api_key=${apiKey}`;
  const options = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  };

  return window.fetch(url, options)
    .then((response) => response.json())
    .then((data) => {
      const variantName = data.variant.name;
      if (variantName === `${this.treatmentName}`) {
        // insert code here to show 'treatment' variant
      } else if (variantName === `${this.controlName}`) {
        // insert code here to show 'control' variant
      } else {
        // unexpected variant name, throw error
        throw new Error(`Unexpected variant name: ${variantName}`);
      }
    })
    .catch((error) => console.error(error));
}

getUserExperimentInfo(apiKey, experimentId, anonymous_id);