Api clients / JavaScript / V3 / Methods

Add A/B Test | JavaScript API Client V3 (Deprecated)

This version of the JavaScript API client has been deprecated in favor of the latest version of the JavaScript API client.

Required API Key: any key with the setSettings ACL
Method signature
analytics.addABTest(object abTest, callback)

About this method

Create an A/B test.

You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants.

Examples

Add an A/B test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$endDate = new \DateTime('tomorrow');
$endDate = $endDate->format('Y-m-d\TH:i:s\Z');


$analytics = AnalyticsClient::create(
  'YourApplicationID',
  'YourWriteAPIKey'
);

$analytics->addABTest([
  'name' => 'myABTest',
  'variants' => [
    [
      'index' => 'indexName1',
      'trafficPercentage' => 90,
      'description' =>  'a description'
    ],
    [
      'index' => 'indexName1-alt',
      'trafficPercentage' => 10
    ],
  ],
  "endAt" => $endDate,
]);

Add an A/B test on a single index with custom search parameters

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$endAt = new DateTime('tomorrow');

$abTest = [
    'name' => 'myABTest',
    'variants' => [
        ['index' => 'indexName1', 'trafficPercentage' => 90],
        [
            'index' => 'indexName1',
            'trafficPercentage' => 10,
            'customSearchParameters' => ['ignorePlurals' => true],
        ],
    ],
    'endAt' => $endAt->format('Y-m-d\TH:i:s\Z'),
];

$response = $analyticsClient->addABTest($abTest);

Parameters

abTest
Required

The definition of the A/B test

{
  "name": name,
  "variants": variants,
  "endAt": endAt
}

abTest object

name
type: string
Required

Name of the A/B test

variants
type: list of variant
Required

List of 2 variants:

  • The base index
  • The index to test against
[
  {
    "index": index,
    "description": description,
    "trafficPercentage": trafficPercentage
  },
  {
    "index": index,
    "description": description,
    "trafficPercentage": trafficPercentage,
    "customSearchParameters": customSearchParameters
  }
]
endAt
type: string
Optional

A date to automatically end an A/B test at a specific time. The date should be in the following format: Y-m-d\TH:i:s\Z

variants ➔ variant

index
type: string
Required

Index name

trafficPercentage
type: integer
Required

Percentage of the traffic that should be going to the variant. The sum of the percentage should be equal to 100.

customSearchParameters
type: key value mapping
Optional

Applies search parameters on a variant. This can only be used if the two variants are using the same index.

Can be one or sereval of the following parameters:

Search

Typo tolerance

Facets

Synonyms

Personalization

Distinct

Geo search

description
type: string
Optional

Description of the variant. This is useful when seeing the results in the dashboard or via the API.

Response

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

JSON format

1
2
3
4
5
{
  "abTestID": 78,
  "taskID": 111885720
  "index": "atis-abtest-default",
}
abTestID
integer

Generated Id of the A/B test.

taskID
integer

The taskID used with the waitTask method.

index
string

Base index name for the A/B test.

Did you find this page helpful?