Namespace: group
Type Aliases
AbTestList
Ƭ AbTestList<T
>: { [testName in T]: Object }
AB test groups configuration format. Contains the relative sizes for each group:
type abTestNames = 'Test_ABTEST' | 'Test2_ABTEST';
const ABTests: AbTestList<abTestNames> = {
Test_ABTEST: {
Test1_group_1: 1, // → 50%
Test1_group_2: 1 // → 50%
},
Test2_ABTEST: {
Test2_group_1: 5, // → 5%
Test2_group_2: 90, // → 90%
Test2_group_3: 5 // → 5%
}
};
Type parameters
Name | Type |
---|---|
T |
extends string |
Config
Ƭ Config: Record
<string
, number
>
Configuration used by select
and random
. Includes group names with their relative weights.
Functions
getAbGroup
▸ getAbGroup<T
>(userId
, testName
, abTestConfig
): keyof AbTestList
<T
>[T
]
Get the AB group of a specific user in a specific AB test.
Type parameters
Name | Type |
---|---|
T |
extends string |
Parameters
Name | Type | Description |
---|---|---|
userId |
string |
Unique static identifier for the user |
testName |
T |
Name of the AB test |
abTestConfig |
AbTestList <T > |
AB test groups configuration |
Returns
keyof AbTestList
<T
>[T
]
getAbGroups
▸ getAbGroups<T
>(userId
, abTestConfig
): Object
Get all AB groups of a specific user.
Type parameters
Name | Type |
---|---|
T |
extends string |
Parameters
Name | Type | Description |
---|---|---|
userId |
string |
Unique static identifier for the user |
abTestConfig |
AbTestList <T > |
AB test groups configuration |
Returns
Object
random
▸ random<T
>(seed
, tag
, config
): keyof T
Deterministically select a random group for a seed from provided group config. The full seed for
the random group will be calculated from the provided seed and tag values. If the seed is a
string it will be converted to a number with parseInt
.
Throws an error if no groups are configured.
Type parameters
Name | Type |
---|---|
T |
extends Config |
Parameters
Name | Type | Description |
---|---|---|
seed |
string | number |
Number part for the seed |
tag |
string |
String part for the seed |
config |
T |
Config for all groups with weights |
Returns
keyof T
select
▸ select<T
>(index
, config
): keyof T
Deterministically select a group for an index from provided group config. The index should be an
evenly distributed number. If the index is a string it will be converted to a number with
parseInt
.
Throws an error if no groups are configured.
Type parameters
Name | Type |
---|---|
T |
extends Config |
Parameters
Name | Type | Description |
---|---|---|
index |
string | number |
Index to use for group selection |
config |
T |
Config for all groups with weights |
Returns
keyof T