abby-client
Version:
This is the client library for Greetz's very own A/B testing platform.
39 lines (30 loc) • 995 B
JavaScript
const sync = require('./sync');
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getVariation(uuid, experiment){
let random = generateRandomNumber(0, 100);
let variation = experiment.variations.filter(variation => {
return random >= variation.rangeStart && random <= variation.rangeEnd;
})
return variation[0].id;
}
function handle(req, res) {
let availableExperiments = {
"experiment_split_homepage": "abby_homepage"
}
req.experiments = availableExperiments;
};
module.exports = function(/**Configs*/configs){
if (!configs || typeof configs !== 'object') {
throw new Error('You should pass config object');
}
else if (!configs.tags) {
throw new Error('You should pass env');
}
else if (!configs.apiEndpoint) {
throw new Error('You should pass API_ENDPOINT');
}
handle.ready = () => sync.load(configs);
return handle;
};