Create an Experiment

Consider this code for creating an experiment:

// Activate user in an experiment
var variant = client.start('some_experiment');

if (variant === 'control') {
  // Execute code for variation 'control'
  hideExtraSection()
} else if (variant === 'treatment') {
  // Execute code for variation 'treatment'
  showExtraSection()
} else {
  // Execute default code
}

The problem with this code is that it is highly unusable. Because you have to hard-code an experiment ID every time, it forces you to change the code powering the experiment every time you want to make any change to it.

Using params

Moonland clients never have any experiment or variant coded in. Instead, Moonland allows you to compose experiment and write reusable code using params.

Here is how the experiment above would look in Moonland:

  var shouldShowExtraSession = moonland.get('DemoNamespace', 'showExtraSession')
  if (shouldShowExtraSession) {
    showExtraSession()
  } else {
    hideExtraSession()
  }

Notice how we have gotten rid of any hardcoded experiment reference. By using reusable params, you can run as many experiments you want without ever having to redeploy your code.