Setup

User identifier

The user identifier or userId is used to uniquely identify the users in your experiments and feature flags. Any string could be supplied but is recommended to use a uuid.

The userId should be persisted somehow. For example, cookies or local storage.

const userId = '676380e0-7793-44d6-9189-eb5868e17a86';

Settings file

The settings file or datafile is just a json that defines the configuration of the experiments and features avaliable.

Ideally this file should be hosted somewhere outside your application, so it could be fetched during boostrap or every certain time. This will allow you to make changes to this file without deploying the whole application.

const datafile = {
experiments: {
'experiment-1': {
id: 'experiment-1',
percentage: 90,
variations: [{
id: '0',
percentage: 50
}, {
id: '1',
percentage: 50
}]
},
'experiment-2': {
id: 'experiment-2',
percentage: 100,
variations: [{
id: '0',
percentage: 100
}],
audience: { // jsonLogic
'==' : [{ var : 'countryCode' }, 'us']
}
}
},
features: {
'feature-1': {
id: 'feature-1',
percentage: 50
}
}
};

The format to define audiences is jsonLogic which allow you to build complex rules as JSON. For example, you can nest rules to target users that are older than 32 years old and are located in 🇻🇪.

const rules = {
and: [
{ '<': [{ var: 'age' }, 32] },
{ '==': [{ var: 'countryCode' }, 've'] }
]
};