Moonland JS Client
The easiest way to manage complex web experiments
Installation
Browser
Download the minified library and insert it in your scripts.
<script src="moonlan-js.min.js"></script>
Node.js
Install it using node or yarn
npm install --save moonland-js
or with yarn if you prefer
yarn add moonland-js
Usage
To get started, just run create a new client
var moonland = new Moonland(options)
Example
var moonland = new Moonland({
apiKey: '<MY_API_KEY>',
defaults: { ... },
units: {
userId: 10,
sessionId: 'a90ad8bb-6f35-4697-844d-6090529aeaf1',
},
mode: 'DEV',
})
The option
object takes the following properties:
Property name | Required | Description |
---|---|---|
apiKey | Yes | The API key associated with the application you want to use. |
defaults | No | 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`. |
Accessing a parameter
In order to get the value of a parameter, simply run
var parameterValue = moonland.get(paramName)
In development, it will simply return the default value specified in the defaults
object.
In production, will either return the default value or will try to allocate it according to the script defined on the server side. It will
The get function has the following signature:
moonland.get(paramName [, units ])
The function get
takes the following parameters:
Parameter name | Description |
---|---|
paramName | The parameter name you want to access |
units | Any additional units you need to use for allocation |
Tracking an event
Tracking events is easy.
moonland.track(eventName [, props] [, units] [, metrics])
In development, track will do nothing.
In production, will send the event to the servers to record the impression.
The function track
takes the following parameters:
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 }`. |