curl --request POST \
--url https://analytics.us.algolia.com/3/abtests \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
{
"name": "Custom ranking sales rank test",
"variants": [
{
"index": "delcourt_production",
"trafficPercentage": 60,
"description": "Current production index"
},
{
"index": "delcourt_production",
"trafficPercentage": 60,
"description": "Current production index"
}
],
"metrics": [
[
{
"name": "revenue",
"dimension": "USD"
},
{
"name": "conversionRate"
},
{
"name": "clickThroughRate"
},
{
"name": "trackedSearchCount"
}
]
],
"configuration": {
"minimumDetectableEffect": {
"size": 0,
"metric": "addToCartRate"
},
"filters": [
{
"domain": "abtesting",
"name": "isOutlier",
"trackEffects": true,
"includes": true
}
],
"errorCorrection": "bonferroni"
},
"endAt": "2023-06-17T00:00:00Z"
}
'// Initialize the client
var client = new AbtestingV3Client(
new AbtestingV3Config(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY",
"ALGOLIA_APPLICATION_REGION"
)
);
// Call the API
var response = await client.AddABTestsAsync(
new AddABTestsRequest
{
EndAt = "2022-12-31T00:00:00.000Z",
Name = "myABTest",
Metrics = new List<CreateMetric> { new CreateMetric { Name = "myMetric" } },
Variants = new List<AddABTestsVariant>
{
new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30 }),
new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50 }),
},
}
);
// print the response
Console.WriteLine(response);// Initialize the client
final client = AbtestingV3Client(
appId: 'ALGOLIA_APPLICATION_ID',
apiKey: 'ALGOLIA_API_KEY',
region: 'ALGOLIA_APPLICATION_REGION');
// Call the API
final response = await client.addABTests(
addABTestsRequest: AddABTestsRequest(
endAt: "2022-12-31T00:00:00.000Z",
name: "myABTest",
metrics: [
CreateMetric(
name: "myMetric",
),
],
variants: [
AbTestsVariant(
index: "AB_TEST_1",
trafficPercentage: 30,
),
AbTestsVariant(
index: "AB_TEST_2",
trafficPercentage: 50,
),
],
),
);
// print the response
print(response);// Initialize the client with your application region, eg. abtestingV3.ALGOLIA_APPLICATION_REGION
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)
}
// Call the API
response, err := client.AddABTests(client.NewApiAddABTestsRequest(
abtestingV3.NewEmptyAddABTestsRequest().SetEndAt("2022-12-31T00:00:00.000Z").SetName("myABTest").SetMetrics(
[]abtestingV3.CreateMetric{*abtestingV3.NewEmptyCreateMetric().SetName("myMetric")}).SetVariants(
[]abtestingV3.AddABTestsVariant{*abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))})))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
AbtestingV3Client client = new AbtestingV3Client("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");
// Call the API
ABTestResponse response = client.addABTests(
new AddABTestsRequest()
.setEndAt("2022-12-31T00:00:00.000Z")
.setName("myABTest")
.setMetrics(Arrays.asList(new CreateMetric().setName("myMetric")))
.setVariants(
Arrays.asList(
new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30),
new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50)
)
)
);
// print the response
System.out.println(response);// Initialize the client
// Replace 'us' with your Algolia Application Region
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initAbtestingV3({ region: 'us' });
// Call the API
const response = await client.addABTests({
endAt: '2022-12-31T00:00:00.000Z',
name: 'myABTest',
metrics: [{ name: 'myMetric' }],
variants: [
{ index: 'AB_TEST_1', trafficPercentage: 30 },
{ index: 'AB_TEST_2', trafficPercentage: 50 },
],
});
// print the response
console.log(response);// Initialize the client
val client =
AbtestingV3Client(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = "ALGOLIA_APPLICATION_REGION",
)
// Call the API
var response =
client.addABTests(
addABTestsRequest =
AddABTestsRequest(
endAt = "2022-12-31T00:00:00.000Z",
name = "myABTest",
metrics = listOf(CreateMetric(name = "myMetric")),
variants =
listOf(
AbTestsVariant(index = "AB_TEST_1", trafficPercentage = 30),
AbTestsVariant(index = "AB_TEST_2", trafficPercentage = 50),
),
)
)
// print the response
println(response)// Initialize the client
$client = AbtestingV3Client::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');
// Call the API
$response = $client->addABTests(
['endAt' => '2022-12-31T00:00:00.000Z',
'name' => 'myABTest',
'metrics' => [
['name' => 'myMetric',
],
],
'variants' => [
['index' => 'AB_TEST_1',
'trafficPercentage' => 30,
],
['index' => 'AB_TEST_2',
'trafficPercentage' => 50,
],
],
],
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use AbtestingV3Client instead, which exposes the exact same methods.
client = AbtestingV3ClientSync(
"ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
)
# Call the API
response = client.add_ab_tests(
add_ab_tests_request={
"endAt": "2022-12-31T00:00:00.000Z",
"name": "myABTest",
"metrics": [
{
"name": "myMetric",
},
],
"variants": [
{
"index": "AB_TEST_1",
"trafficPercentage": 30,
},
{
"index": "AB_TEST_2",
"trafficPercentage": 50,
},
],
},
)
# print the response
print(response)# Initialize the client
client = Algolia::AbtestingV3Client.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
# Call the API
response = client.add_ab_tests(
Algolia::AbtestingV3::AddABTestsRequest.new(
end_at: "2022-12-31T00:00:00.000Z",
name: "myABTest",
metrics: [Algolia::AbtestingV3::CreateMetric.new(name: "myMetric")],
variants: [
Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30),
Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50)
]
)
)
# print the response
puts(response)// Initialize the client
val client = AbtestingV3Client(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = Option("ALGOLIA_APPLICATION_REGION")
)
// Call the API
val response = Await.result(
client.addABTests(
addABTestsRequest = AddABTestsRequest(
endAt = "2022-12-31T00:00:00.000Z",
name = "myABTest",
metrics = Seq(
CreateMetric(
name = "myMetric"
)
),
variants = Seq(
AbTestsVariant(
index = "AB_TEST_1",
trafficPercentage = 30
),
AbTestsVariant(
index = "AB_TEST_2",
trafficPercentage = 50
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try AbtestingV3Client(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)
// Call the API
let response = try await client.addABTests(addABTestsRequest: AbtestingV3AddABTestsRequest(
name: "myABTest",
variants: [
AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
index: "AB_TEST_1",
trafficPercentage: 30
)),
AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
index: "AB_TEST_2",
trafficPercentage: 50
)),
],
metrics: [CreateMetric(name: "myMetric")],
endAt: "2022-12-31T00:00:00.000Z"
))
// print the response
print(response){
"abTestID": 224,
"index": "delcourt_production",
"taskID": 1514562690001
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}Create an A/B test
Creates a new A/B test.
curl --request POST \
--url https://analytics.us.algolia.com/3/abtests \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
{
"name": "Custom ranking sales rank test",
"variants": [
{
"index": "delcourt_production",
"trafficPercentage": 60,
"description": "Current production index"
},
{
"index": "delcourt_production",
"trafficPercentage": 60,
"description": "Current production index"
}
],
"metrics": [
[
{
"name": "revenue",
"dimension": "USD"
},
{
"name": "conversionRate"
},
{
"name": "clickThroughRate"
},
{
"name": "trackedSearchCount"
}
]
],
"configuration": {
"minimumDetectableEffect": {
"size": 0,
"metric": "addToCartRate"
},
"filters": [
{
"domain": "abtesting",
"name": "isOutlier",
"trackEffects": true,
"includes": true
}
],
"errorCorrection": "bonferroni"
},
"endAt": "2023-06-17T00:00:00Z"
}
'// Initialize the client
var client = new AbtestingV3Client(
new AbtestingV3Config(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY",
"ALGOLIA_APPLICATION_REGION"
)
);
// Call the API
var response = await client.AddABTestsAsync(
new AddABTestsRequest
{
EndAt = "2022-12-31T00:00:00.000Z",
Name = "myABTest",
Metrics = new List<CreateMetric> { new CreateMetric { Name = "myMetric" } },
Variants = new List<AddABTestsVariant>
{
new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30 }),
new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50 }),
},
}
);
// print the response
Console.WriteLine(response);// Initialize the client
final client = AbtestingV3Client(
appId: 'ALGOLIA_APPLICATION_ID',
apiKey: 'ALGOLIA_API_KEY',
region: 'ALGOLIA_APPLICATION_REGION');
// Call the API
final response = await client.addABTests(
addABTestsRequest: AddABTestsRequest(
endAt: "2022-12-31T00:00:00.000Z",
name: "myABTest",
metrics: [
CreateMetric(
name: "myMetric",
),
],
variants: [
AbTestsVariant(
index: "AB_TEST_1",
trafficPercentage: 30,
),
AbTestsVariant(
index: "AB_TEST_2",
trafficPercentage: 50,
),
],
),
);
// print the response
print(response);// Initialize the client with your application region, eg. abtestingV3.ALGOLIA_APPLICATION_REGION
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)
}
// Call the API
response, err := client.AddABTests(client.NewApiAddABTestsRequest(
abtestingV3.NewEmptyAddABTestsRequest().SetEndAt("2022-12-31T00:00:00.000Z").SetName("myABTest").SetMetrics(
[]abtestingV3.CreateMetric{*abtestingV3.NewEmptyCreateMetric().SetName("myMetric")}).SetVariants(
[]abtestingV3.AddABTestsVariant{*abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtestingV3.AbTestsVariantAsAddABTestsVariant(
abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))})))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
AbtestingV3Client client = new AbtestingV3Client("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");
// Call the API
ABTestResponse response = client.addABTests(
new AddABTestsRequest()
.setEndAt("2022-12-31T00:00:00.000Z")
.setName("myABTest")
.setMetrics(Arrays.asList(new CreateMetric().setName("myMetric")))
.setVariants(
Arrays.asList(
new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30),
new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50)
)
)
);
// print the response
System.out.println(response);// Initialize the client
// Replace 'us' with your Algolia Application Region
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initAbtestingV3({ region: 'us' });
// Call the API
const response = await client.addABTests({
endAt: '2022-12-31T00:00:00.000Z',
name: 'myABTest',
metrics: [{ name: 'myMetric' }],
variants: [
{ index: 'AB_TEST_1', trafficPercentage: 30 },
{ index: 'AB_TEST_2', trafficPercentage: 50 },
],
});
// print the response
console.log(response);// Initialize the client
val client =
AbtestingV3Client(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = "ALGOLIA_APPLICATION_REGION",
)
// Call the API
var response =
client.addABTests(
addABTestsRequest =
AddABTestsRequest(
endAt = "2022-12-31T00:00:00.000Z",
name = "myABTest",
metrics = listOf(CreateMetric(name = "myMetric")),
variants =
listOf(
AbTestsVariant(index = "AB_TEST_1", trafficPercentage = 30),
AbTestsVariant(index = "AB_TEST_2", trafficPercentage = 50),
),
)
)
// print the response
println(response)// Initialize the client
$client = AbtestingV3Client::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');
// Call the API
$response = $client->addABTests(
['endAt' => '2022-12-31T00:00:00.000Z',
'name' => 'myABTest',
'metrics' => [
['name' => 'myMetric',
],
],
'variants' => [
['index' => 'AB_TEST_1',
'trafficPercentage' => 30,
],
['index' => 'AB_TEST_2',
'trafficPercentage' => 50,
],
],
],
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use AbtestingV3Client instead, which exposes the exact same methods.
client = AbtestingV3ClientSync(
"ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
)
# Call the API
response = client.add_ab_tests(
add_ab_tests_request={
"endAt": "2022-12-31T00:00:00.000Z",
"name": "myABTest",
"metrics": [
{
"name": "myMetric",
},
],
"variants": [
{
"index": "AB_TEST_1",
"trafficPercentage": 30,
},
{
"index": "AB_TEST_2",
"trafficPercentage": 50,
},
],
},
)
# print the response
print(response)# Initialize the client
client = Algolia::AbtestingV3Client.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
# Call the API
response = client.add_ab_tests(
Algolia::AbtestingV3::AddABTestsRequest.new(
end_at: "2022-12-31T00:00:00.000Z",
name: "myABTest",
metrics: [Algolia::AbtestingV3::CreateMetric.new(name: "myMetric")],
variants: [
Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30),
Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50)
]
)
)
# print the response
puts(response)// Initialize the client
val client = AbtestingV3Client(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = Option("ALGOLIA_APPLICATION_REGION")
)
// Call the API
val response = Await.result(
client.addABTests(
addABTestsRequest = AddABTestsRequest(
endAt = "2022-12-31T00:00:00.000Z",
name = "myABTest",
metrics = Seq(
CreateMetric(
name = "myMetric"
)
),
variants = Seq(
AbTestsVariant(
index = "AB_TEST_1",
trafficPercentage = 30
),
AbTestsVariant(
index = "AB_TEST_2",
trafficPercentage = 50
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try AbtestingV3Client(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)
// Call the API
let response = try await client.addABTests(addABTestsRequest: AbtestingV3AddABTestsRequest(
name: "myABTest",
variants: [
AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
index: "AB_TEST_1",
trafficPercentage: 30
)),
AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
index: "AB_TEST_2",
trafficPercentage: 50
)),
],
metrics: [CreateMetric(name: "myMetric")],
endAt: "2022-12-31T00:00:00.000Z"
))
// print the response
print(response){
"abTestID": 224,
"index": "delcourt_production",
"taskID": 1514562690001
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}editSettingsAuthorizations
Your Algolia application ID.
Your Algolia API key with the necessary permissions to make the request. Permissions are controlled through access control lists (ACL) and access restrictions. The required ACL to make a request is listed in each endpoint's reference.
Body
End date and time of the A/B test, in RFC 3339 format.
"2023-06-17T00:00:00Z"
A/B test metrics involved in the test. Only these metrics will be considered when calculating results.
Show child attributes
Show child attributes
A/B test name.
"Custom ranking sales rank test"
A/B test variants.
2- Variant
- Variant with search parameters
Show child attributes
Show child attributes
A/B test configuration.
Show child attributes
Show child attributes
Response
OK
Unique A/B test identifier.
224
Index name of the A/B test variant (case-sensitive).
"delcourt_production"
Unique identifier of a task.
A successful API response means that a task was added to a queue.
It might not run immediately.
You can check the task's progress with the task operation and this task ID.
1514562690001
Was this page helpful?