Variation Distribution
When running an A/B Test, you need to assign users to Variations and implement logic for each Variation. You can use the Hackle SDK to handle this user distribution.
variation
Pass the Experiment Key to the variation() method to assign users to a Variation and receive the result.
Experiment Key (key)
int
Required
-
Example
In the example code below, Experiment Key 42 is passed, and there are two Variations: A and B.
import "package:hackle/hackle.dart";
// Determines which Variation to show to the user in the A/B Test with Experiment Key 42.
// Returns Variation A if a decision cannot be made.
Variation variation = await HackleApp.variation(42);
// Logic for the assigned Variation
if (variation == Variation.A) {
// Group A logic
} else {
// Group B logic
}variationDetail
The variationDetail() method works the same as variation() but additionally 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. In the example below, Experiment Key 42 is passed.
Decision Reason
The decision reason is returned in a format such as SDK_NOT_READY. Refer to 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
You can also receive the parameter values for the assigned Variation through the
variationDetail()method.The
Decisioninstance returned byvariationDetail()contains aParameterConfigobject with the full parameter configuration.Since parameter values configured in the Hackle A/B Test screen are stored as key-value pairs, use the methods below according to the parameter type to retrieve the configured values.
Use the following functions to retrieve the values configured for the assigned Variation.
getString
Returns parameter values configured as STRING or JSON type.
getInt
Returns parameter values configured as NUMBER type as an Int.
getDouble
Returns parameter values configured as NUMBER type as a Double.
getBool
Returns parameter values configured as Boolean type.
Example
Last updated