Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A/B testing with Confidence
var confidence = require('../');
// Master configuration
var master = {
key1: 'abc',
key2: {
$filter: 'env',
production: 1,
$default: 2
},
key3: {
$filter: 'random.a',
$id: 'random_ab_test',
$range: [
{ limit: 10, value: 3 },
{ limit: 50, value: 4 }
],
$default: 5
}
};
var store = new confidence.Store(master);
// On first visit, generate a GUID for the client
var guid = confidence.id.generate();
// When the client comes back requesting it's configuration,
// convert the id to a criteria object
var criteria = confidence.id.criteria(guid);
// Check if the id is valid (generated according to the even
// distribution randomness rules)
if (criteria === null) {
console.err('Bad id');
process.exit(1);
}
// Set any other criterion such as environment
criteria.env = 'production';
// Compile the client-specific configuration using the
// master and criteria
var config = store.get('/', criteria);
// Return the config to the client
console.log(config);
process.exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.