Hello! Have a problem with traffic split configura...
# give-feedback
l
Hello! Have a problem with traffic split configuration in experiments. My configuration in the Growthbook is 100% traffic, 50/20/5/25 split. I created script to make 100 requests with 100ms delay between each and i got result like this:
Copy code
{0: 29, 1: 35, 2: 18, 3: 18}
How to achieve my configured split for traffic?
f
Can you share the script you used?
l
Yes of course. It is very simple:
Copy code
<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>
f
It looks like you are using an inline experiment with the SDK (the
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:
Copy code
growthbook.run({
  key: "TomekTest",
  variations: ["Tomek", "Mikolaj", "Jedrzej", "Przemek"],
  weights: [0.5, 0.2, 0.05, 0.25]
})
Our automated test suite for the javascript SDK does simulations with 10,000 users to ensure the variation weighting is equal. https://github.com/growthbook/growthbook/blob/main/packages/sdk-js/test/experiments.test.ts#L473
l
Thanks for explain the problem. So in that case I have one more question. If I set a traffic in experiments, how I can use it on my page?
I think about that:
f
It's a little confusing, but that UI is only for documentation/analysis purposes. We use it to check that the data coming in matches the expected traffic split (i.e. an SRM check). The only way to pass traffic split settings from the GrowthBook app into the SDK is by using feature flags.
l
Great. Got it! Thanks a lot for help.
h
This has been confusing for more than few people. I suggest adding a banner with information or maybe a docs page on how to use feature tab, and how to connect feature to an experiment
👍 1