Traffic Distribution

When conducting an A/B test, not only do you need to distribute your users to different test groups, you also need to write a logic for each test group. After the integration stages, the distribution of users into different test groups can be done through the Hackle SDK.

📘

Test Groups

The test groups are basically the different groups that are exposed to the versions (features, screens, algorithms, etc) of a page of an experiment. Test groups include both the control test group A and treatment test groups B, C, D, etc., that are exposed to the "improved" versions of the pages.
The test groups can be set on the dashboard and further information on the test groups can be found on the What is a Test Group? document.

variation

Think of the variation as the term that is equivalent to different versions of the page being shown to users on your app or browser.
By passing the experiment key to the variation() method, you can distribute users and receive the result for the specific experiment. After that, we implement the logic of the page version applicable for each test group.

In the example code below, we are passing an experiment key of 42, and there are two test groups, A and B.

// Determines the test group to assign the user in an A/B tests with an experiment key of 42.
// For undetermined cases, the user is returned to test group A.
let variation = hackleApp.variation(experimentKey: 42)

// Logic for the different test groups. 
if variation == "A" {
  // Logic for test group A
} else if variation == "B" {
  // Logic for test group B
}
// Determines the test group to assign the user in an A/B tests with an experiment key of 42.
// For undetermined cases, the user is returned to test group A.
NSString *variation = [app variationWithExperimentKey:42 defaultVariation:@"A"];

// Logic for the different test groups. 
if([variation isEqual:@"A"]) {
    // Logic for test group A
} else if ([variation isEqual:@"B"]) {
    // Logic for test group B
}

variationDetail

The variationDetail() method works the same as the variation() method but provides the reason behind why a user is distributed to a specific group. This method can be a useful tool to see if the distribution is working properly.
You must pass the experiment key as a parameter. For the example code below, we are passing experimental key 42.

// Traffic distribution details 
let decision: Decision = hackleApp.variationDetail(experimentKey: 42)

// Test group determined from traffic distribution
let variation: String = decision.variation

// Reason for distribution to a specific test group
let reason: String = decision.reason
// Traffic distribution details 
Decision *decision = [hackleApp variationDetailWithExperimentKey:@42 defaultVariation:@"A"];

// Test group determined from traffic distribution
NSString *variation = [decision variation];

// Reason for distribution to a specific test group
NSString *reason = [decision reason];

You will receive the reason for the distribution or the allocation of a specific user to a specific test group in the form of SDK_NOT_READY. Please refer to the table below for the full list of different distribution reasons.

ReasonDescriptionDistribution Result
SDK_NOT_READYThe SDK is not ready to use.
(e.g. initialized with the wrong SDK key)
(control) Test Group A
EXPERIMENT_NOT_FOUNDNo A/B tests were found for the experimental key you passed.
The experiment key may be incorrect or the experiment may be in the archive status.
(control) Test Group A
EXPERIMENT_DRAFTThe A/B test is ready to start.(control) Test Group A
EXPERIMENT_PAUSEDThe A/B test has been paused.(control) Test Group A
EXPERIMENT_COMPLETEDA/B test has ended.Final winning test group from the experiment
OVERRIDDENUsers are distributed to a specific test group by manual assignment.Manually assigned test group
NOT_IN_EXPERIMENT_TARGETUser does not qualify as the target user for the A/B test.(control) Test Group A
TRAFFIC_NOT_ALLOCATEDThe user is qualified as a target user of the A/B test but is not included as a part of the traffic.(control) Test Group A
TRAFFIC_ALLOCATEDUser has been assigned to A/B test.Assigned test group
VARIATION_DROPPEDThe test group was removed from the A/B test.(control) Test Group A
EXCEPTIONAn unknown error has occurred.(control) Test Group A

Parameter

  • Parameter values of the distributed group can also be provided through the variationDetail() method.
  • In the Decision instance passed through the variationDetail() method, there is a ParameterConfig object which contains all parameter setting information.
  • Parameter values you've set on the dashboard exists in the form of key and value, therefore you can use the method below to set the parameter values.

📘

Parameter setting is only available for SDK version 2.9.0 or higher.

getString

  • Returns the parameter value set to STRING, JSON type.
  • Returns the set value of the distributed group.
let decision: Decision = hackleApp.variationDetail(experimentKey: 42)
let config: ParameterConfig = decision.config

let strValue: String = decision.getString(forKey: "parameter_key_string_type", defaultValue: "defaultValue")
let strValueInConfig: String = config.getString(forKey: "parameter_key_string_type", defaultValue: "defaultValue")

let jsonValue: String = decision.getString(forKey: "parameter_key_json_type", defaultValue: "defaultValue")
let jsonValueInConfig: String = config.getString(forKey: "parameter_key_json_type", defaultValue: "defaultValue")
Decision *decision = [hackleApp variationDetailWithExperimentKey:@42 defaultVariation:@"A"];

NSString *stringValue = [decision getStringForKey:@"parameter_key_string_type" defaultValue:@"defaultValue"];

NSString *jsonValue = [decision getStringForKey:@"parameter_key_json_type" defaultValue:@"defaultValue"];

getInt

  • Returns the parameter value set to Number type as Int type.
  • Returns the set value of the distributed group.
let decision: Decision = hackleApp.variationDetail(experimentKey: 42)
let config: ParameterConfig = decision.config

let intValue: Int = decision.getInt(forKey: "parameter_key_number_type", defaultValue: 0)
let intValueInConfig: Int = config.getInt(forKey: "parameter_key_number_type", defaultValue: 0)
Decision *decision = [hackleApp variationDetailWithExperimentKey:@42 defaultVariation:@"A"];

int intValue = [decision getIntForKey:@"parameter_key_number_type" defaultValue:@0];

getDouble

  • Returns the parameter value set to Number type as Double type.
  • Returns the set value of the distributed group.
let decision: Decision = hackleApp.variationDetail(experimentKey: 42)
let config: ParameterConfig = decision.config

let doubleValue: Double = decision.getDouble(forKey: "parameter_key_number_type", defaultValue: 0.0)
let doubleValueInConfig: Double = config.getDouble(forKey: "parameter_key_number_type", defaultValue: 0.0)
Decision *decision = [hackleApp variationDetailWithExperimentKey:@42 defaultVariation:@"A"];

double doubleValue = [decision getDoubleForKey:@"parameter_key_number_type" defaultValue:0.0];

getBool

  • Returns the parameter value set to Boolean type.
  • Returns the set value of the distributed group.
let decision: Decision = hackleApp.variationDetail(experimentKey: 42)
let config: ParameterConfig = decision.config

let boolValue: Bool = decision.getBool(forKey: "parameter_key_boolean_type", defaultValue: false)
let boolValueInConfig: Bool = config.getBool(forKey: "parameter_key_boolean_type", defaultValue: false)
Decision *decision = [hackleApp variationDetailWithExperimentKey:@42 defaultVariation:@"A"];

bool boolValue = [decision getBoolForKey:@"parameter_key_boolean_type" defaultValue:false];