Traffic Distribution

When conducting an A/B test, you need to distribute users to the test groups and write the logic corresponding to each test group. User allocation can be done through the Hackle SDK.

📘

Test Groups

Test groups refer to the existing versions, including the control group (baseline) and the treatment group(s), where the treatment group can consist of one or more variations. These can be configured in the dashboard, and you can learn more about managing test groups in the A/B Test Settings document.

Variation

By passing an experiment key and user to the Variation() method, you can distribute users and receive the results. Then, you implement the logic for each test group.

In the example code below, we are passing experiment key 42 and user identifier "ae2182e0." There are two test groups: A and B.

import "github.com/hackle-io/hackle-go-sdk/hackle"

// In an A/B test with experiment key 42,
// decide which test group to expose the user with identifier "ae2182e0."
// If no decision can be made, it returns test group A by default.
user := hackle.NewUserBuilder().ID("ae2182e0").Build()
variation := hackleClient.Variation(42, user)

// Implement logic for the assigned group
if variation == "A" {
  // Logic for group A
} else {
  // Logic for group B
}

VariationDetail

The VariationDetail() method functions the same as the Variation() method but additionally provides the reason for the specific group allocation. This method can be useful when examining whether distribution is functioning correctly.

You need to pass the experiment key as a parameter. In the example code below, we are passing experiment key 42.

import "github.com/hackle-io/hackle-go-sdk/hackle" 

// Detailed distribution decision
decision := hackleClient.VariationDetail(42, user)

// Assigned group
variation := decision.Variation()

// Distribution decision reason
reason := decision.Reason()

The distribution decision reason is received in a format like SDK_NOT_READY. You can refer to the table below for more details:

Reason

Description

Distribution Result

SDK_NOT_READY

The SDK is not ready for use.
(e.g., attempting initialization with an incorrect SDK key)

Default group (A)

EXPERIMENT_NOT_FOUND

The A/B test for the provided experiment key cannot be found.
The experiment key may be incorrect or the experiment could be in a storage state.

Default group (A)

NOT_IN_MUTUAL_EXCLUSION_EXPERIMENT

The experiment is included in mutual exclusion settings, but the user is not assigned to that mutual exclusion group.

Default group (A)

EXPERIMENT_DRAFT

The A/B test is in a draft state.

Default group (A)

EXPERIMENT_PAUSED

The A/B test is in a paused state.

Default group (A)

EXPERIMENT_COMPLETED

The A/B test has ended.

The winning group selected at the end

OVERRIDDEN

The user has been manually assigned to a specific group by manual allocation.

Manually allocated group

NOT_IN_EXPERIMENT_TARGET

The user is not part of the A/B test target.

Default group (A)

TRAFFIC_NOT_ALLOCATED

The A/B test is running, but the user has not been allocated to the test.

Default group (A)

TRAFFIC_ALLOCATED

The user has been allocated to the A/B test.

Allocated group

VARIATION_DROPPED

The originally allocated group has been excluded from the test.

Default group (A)

EXCEPTION

An unknown error has occurred.

Default group (A)

Parameters

  • You can also receive the parameter values for the distributed group using the VariationDetail() method.
  • Since Hackle's A/B test settings often include parameters in the form of key-value pairs, you can use the following methods to access and utilize these parameter values based on their types:

GetString

  • Returns the parameter value set as STRING or JSON in the group's configuration.
  • Retrieves the configured value for the distributed group.
import "github.com/hackle-io/hackle-go-sdk/hackle"

decision := hackleClient.VariationDetail(42, user)
  
stringValue := decision.GetString("string_key", "default_value")
jsonValue := decision.GetString("json_key", "{}")

GetNumber

  • Returns the parameter value set as a Number type as a float64.
  • Retrieves the configured value for the distributed group.
import "github.com/hackle-io/hackle-go-sdk/hackle"

decision := hackleClient.VariationDetail(42, user)

number := decision.GetNumber("number_key", 42.0)

GetBool

  • Returns the parameter value set as a boolean type.
  • Retrieves the configured value for the distributed group.
import "github.com/hackle-io/hackle-go-sdk/hackle"

decision := hackleClient.VariationDetail(42, user)

boolValue := decision.GetBool("bool_key", false)