straight-businessperson-54316
10/25/2021, 3:20 PMfuture-teacher-7046
straight-businessperson-54316
10/26/2021, 7:39 AMfuture-teacher-7046
// variations would come from the api instead of being hardcoded
const {value} = runExperiment({
key: "my-test"
})
button.color = value
Or Remote Configuration where you just ask for a value and any relevant experiments are run automatically?
// If an experiment is running, it will return a variation
// Otherwise, it will return a default constant value
button.color = getConfig("signup.button.color")
straight-businessperson-54316
11/08/2021, 11:48 AMconst config = 'An http request to the config on the CDN';
/**
* Config should contains Variations:
* {
* "status": 200,
* "overrides": {
* "button-color": {
* "status": "running",
* "coverage": 1,
* "variations": [{
* "name": "Control",
* "id": "green",
* "json": {
* "btnTextColor": "#4F5541",
* "btnBgColor": "#E5F7B8",
* },
* },{
* "name": "Variation 1",
* "id": "white",
* "json": {
* "btnTextColor": "#3DA8DE",
* "btnBgColor": "#FFFFFF",
* },
* }]
* "weights": [
* 0.5,
* 0.5
* ]
* }
* }
* }
*/
const growthbook = new GrowthBook({
user: {
id: userId,
},
groups: {
internal: true,
},
trackingCallback: async (experiment, result) => {
await mixpanel.batchTrack([
{
eventName: 'experiment_started',
userId,
additionalProperties: {
experiment_id: experiment.key,
variation_id: result.variation.id,
},
},
]);
},
});
// HERE I CAN DYNAMICALLY ASSIGN MY USER TO AN EXPERIMENT
Object.keys(config.overrides).forEach((test) => {
const { inExperiment, variationId, value, hashAttribute, hashValue } = growthbook.run({
key: test,
variations: config.overrides[test].variations,
groups: ['internal'],
});
});
If variations
property become available soon in the config, we will definitely move forward to use growthbook in production.
Many thanks!
PS: having access to Json Value is also important since we could host the example above on a dedicated service that could be consumed by any of our clients (ios, android, web...) and return them the appropriate json config.future-teacher-7046