Variation Distribution
When running an A/B Test, you need to distribute users across variations and write logic for each variation. You can use the Hackle SDK to handle this distribution.
variation
Pass the Experiment Key to the variation() method to distribute the user and receive the result.
Experiment Key (key)
int
Required
-
Example
The example code below passes Experiment Key 42, where there are two variations: A and B.
// Decides the variation to expose to the user in the A/B Test with Experiment Key 42.
// Returns variation A if the variation cannot be decided.
let variation = hackleApp.variation(experimentKey: 42)
// Logic for the assigned variation
if variation == "A" {
// Logic for variation A
} else if variation == "B" {
// Logic for variation B
}// Decides the variation to expose to the user in the A/B Test with Experiment Key 42.
// Returns variation A if the variation cannot be decided.
NSString *variation = [app variationWithExperimentKey:42];
// Logic for the assigned variation
if([variation isEqual:@"A"]) {
// Logic for variation A
} else if ([variation isEqual:@"B"]) {
// Logic for variation B
}variationDetail
The variationDetail() method works the same as variation() but also provides the reason for the distribution decision. This method is useful for verifying that distribution is working correctly.
Experiment Key (key)
int
Required
-
Example
You must pass the Experiment Key as a parameter. The example code below passes Experiment Key 42.
Distribution Reason
The distribution reason is returned in the format SDK_NOT_READY. See the table below for details.
SDK_NOT_READY
The SDK is not ready to use.
(e.g., initialization attempted with an invalid SDK Key)
A (Control Group)
EXPERIMENT_NOT_FOUND
No A/B Test was found for the provided Experiment Key. The Experiment Key may be incorrect, or the experiment may be archived.
A (Control Group)
NOT_IN_MUTUAL_EXCLUSION_EXPERIMENT
The experiment is included in Mutually Exclusive Settings, but the user was not assigned to that Mutually Exclusive Group.
A (Control Group)
EXPERIMENT_DRAFT
The A/B Test is in draft state.
A (Control Group)
EXPERIMENT_PAUSED
The A/B Test is paused.
A (Control Group)
EXPERIMENT_COMPLETED
The A/B Test has ended.
Winning Variation selected at completion
OVERRIDDEN
The user was assigned to a specific group by Override.
Override-assigned group
NOT_IN_EXPERIMENT_TARGET
The user is not an A/B Test target.
A (Control Group)
TRAFFIC_NOT_ALLOCATED
The A/B Test is running, but the user was not allocated to the test.
A (Control Group)
TRAFFIC_ALLOCATED
The user has been allocated to the A/B Test.
Allocated group
VARIATION_DROPPED
The originally allocated group has been removed from the test.
A (Control Group)
INVALID_INPUT
The input value is invalid.
A (Control Group)
EXCEPTION
An unknown error occurred.
A (Control Group)
Parameters
The
variationDetail()method also returns the parameter values for the assigned variation.The
Decisioninstance returned byvariationDetail()contains aParameterConfigobject with all parameter configuration.Since parameters set on the Hackle A/B Test screen exist as key-value pairs, you can use the methods below to retrieve parameter values according to the configured parameter type.
You can query the configured values for the assigned variation using the functions below.
getString
Returns a parameter value configured as STRING or JSON type.
getInt
Returns a parameter value configured as NUMBER type as an Int.
getDouble
Returns a parameter value configured as NUMBER type as a Double.
getBool
Returns a parameter value configured as Bool type.
Example
Last updated