Javascript API

Use the Javascript library to run experiments on NodeJS and browsers.

Overview

The Moonland API is very simple, and only composed of 3 methods:


Reference

new Moonland

Creates a new instance of the client. Since the client is stateful, we let you manage the state as you prefer. For Flux applications, we recommend storing the client in the state.

Property Name Required Description
APIKey Yes The API key associated with the application you want to use.
defaults Yes All the defaults for the experiment.
units No An object with all the units you want to record in the session.
mode No Specify the mode in which the library is running. Either DEV or PROD . Default value: PROD

Note:

The behaviour of the library will change drastically depending on wether the library is in PROD mode or DEV mode. In DEV mode, we will not be fetching the new experiments from the serverside nor track any


Get

Get is used to access a param with its namespace.

moonland.get(namespaceName, paramName [, units ])

In DEV, it will simply return the default value specified in the defaults object.

In PROD, will either return the default value or will try to allocate it according to the script defined on the server side. It will

The function get takes the following parameters:

Parameter name Description
namespaceName The name of the namespace you want to access
paramName The parameter name you want to access
units Any additional units you need to use for allocation

Track

Tack is used to send events for collections and determine the success of an A/B experiment.

moonland.track(eventName [, props] [, units] [, metrics])
  • In DEV, track will do nothing.
  • In PROD, will send the event to the servers to record the impression.
Parameter name Description
eventName The name of the event you want to track.
props Any additional parameters you want to track.
units Any additional units you want to track. Units that have been specified in the global configuration will also be tracked.
metrics Any metric you want to track. Metrics take the form `{ revenue: 30.1, cost: 22 }`.