Jun 23, 2025
Estimate the sample size and duration of an A/B test
Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic.
Usage
Required ACL:
analytics
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import abtestingV3 "github.com/algolia/algoliasearch-client-go/v4/algolia/abtesting-v3"
client, err := abtestingV3.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", abtestingV3.US)
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
response, err := client.EstimateABTest(client.NewApiEstimateABTestRequest(
abtestingV3.NewEmptyEstimateABTestRequest().SetConfiguration(
abtestingV3.NewEmptyEstimateConfiguration().SetMinimumDetectableEffect(
abtestingV3.NewEmptyMinimumDetectableEffect().SetSize(0.03).SetMetric(abtestingV3.EffectMetric("conversionRate")))).SetVariants(
[]abtestingV3.AddABTestsVariant{*abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(50)), *abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))})))
if err != nil {
// handle the eventual error
panic(err)
}
Did you find this page helpful?