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

circle-info

When using the Java/Kotlin SDK, duplicate exposure events for the same A/B Test distribution result triggered consecutively by the same user within 1 minute are removed.

Events within 1 minute are counted as 1 occurrence.

circle-exclamation

Pass the Experiment Key and User Identifier to the variation() method to assign users to a Variation and receive the result. Then implement logic for each Variation.

In the example code below, Experiment Key 42 is passed and the User Identifier is "ae2182e0". There are two Variations: A and B.

import io.hackle.sdk.HackleClient
import io.hackle.sdk.common.Variation

// Determines which Variation to show to the user identified as "ae2182e0"
// in the A/B Test with Experiment Key 42.
// Returns Variation A if a decision cannot be made.
val variation: Variation = hackleClient.variation(42, "ae2182e0")

// Logic for the assigned Variation
if (variation == Variation.A) {
  // Group A logic
} else if (variation == Variation.B) {
  // Group B logic
}

variationDetail

The variationDetail() method works the same as variation() but additionally provides the reason for being assigned to a specific group. This method is useful for verifying that distribution is working correctly. You must pass the Experiment Key as a parameter. In the example code below, Experiment Key 42 is passed.

The decision reason is returned in a format such as SDK_NOT_READY. Refer to the table below for details.

Distribution Reason
Description
Distribution Result

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 Decision instance returned by variationDetail() contains a ParameterConfig object 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.

getString

  • Returns parameter values configured as STRING or JSON type.

  • Returns the value configured for the assigned Variation.

getInt

  • Returns parameter values configured as Number type as an Int.

  • Returns the value configured for the assigned Variation.

getDouble

  • Returns parameter values configured as Number type as a Double.

  • Returns the value configured for the assigned Variation.

getLong

  • Returns parameter values configured as Number type as a Long.

  • Returns the value configured for the assigned Variation.

getBoolean

  • Returns parameter values configured as Boolean type.

  • Returns the value configured for the assigned Variation.

Last updated