lemon-iron-16918
08/17/2022, 12:22 PM{0: 29, 1: 35, 2: 18, 3: 18}
How to achieve my configured split for traffic?future-teacher-7046
lemon-iron-16918
08/17/2022, 2:01 PM<script type="module">
import {GrowthBook} from "<https://unpkg.com/@growthbook/growthbook/dist/bundles/esm.min.js>";
async function calculate() {
const sleep = ms => new Promise(r => setTimeout(r, ms));
const requests = 10;
const variations = {
Tomek: 0,
Mikolaj: 0,
Jedrzej: 0,
Przemek: 0
}
for (var i = 0; i < requests; i++) {
const growthbook = new GrowthBook({user: {id: Math.random() * 100}});
fetch("<http://growthbook-api/api/features/KEY>")
.then((res) => res.json())
.then((parsed) => {
const {
inExperiment,
hashUsed,
variationId,
value,
hashAttribute,
hashValue,
} = growthbook.run({
key: "TomekTest",
variations: ["Tomek", "Mikolaj", "Jedrzej", "Przemek"],
});
// console.log(inExperiment,
// hashUsed,
// variationId,
// value,
// hashAttribute,
// hashValue);
variations[value] = variations[value] + 1;
if (i == requests - 1) {
console.log(variations);
}
});
await sleep(100);
}
}
calculate();
</script>
future-teacher-7046
growthbook.run
method). That will not use feature flags or the traffic split defined in the GrowthBook UI. By default it does an even split (so 25/25/25/25). Given the very small sample size, seeing a range of 18-35 seems reasonable.
If you want to use feature flags and the weights defined within the GrowthBook UI, instead of growthbook.run, you'll want to use growthbook.evalFeature("my-feature-key")
.
Or, if you want to continue doing an inline experiment, you can control the weights in code:
growthbook.run({
key: "TomekTest",
variations: ["Tomek", "Mikolaj", "Jedrzej", "Przemek"],
weights: [0.5, 0.2, 0.05, 0.25]
})
lemon-iron-16918
08/17/2022, 2:15 PMfuture-teacher-7046
lemon-iron-16918
08/17/2022, 2:21 PMhallowed-portugal-31753
08/18/2022, 1:58 AM