# Custom A/B Test Segmentation

Each machine learning model deployed to your app includes an associated [A/B test split](https://docs.contextsdk.com/other/glossary#a-b-test-split). This allows us to accurately compare performance data between control and treatment groups, ensuring that observed changes are driven by our model rather than by random variation or other product-level adjustments.

We provide two options for configuring the A/B test split:

### Built-In A/B Test Mechanism (Recommended)

We recommend using our built-in A/B test mechanism, which automates split assignment, deployment, and metric adjustments on your behalf.

No action is required to opt in to this approach.

Refer to [Analytics & Reporting](/context-decision/advanced/analytics-and-reporting.md) to learn how to report user segmentation groups to your internal analytics system.

### Custom A/B Test Segmentation

If your app requires direct control over A/B test segmentation, we also support that, and it takes 2 simple steps:

#### Step 1: Segment Your Users

{% tabs %}
{% tab title="iOS" %}

```swift
ContextManager.setDecisionsEnabled(enabled: false)
```

{% endtab %}

{% tab title="Android" %}
Not yet supported in Android. Reach out to our team to request this feature.
{% endtab %}

{% tab title="Flutter" %}
Not yet supported in Flutter. Reach out to our team to request this feature.
{% endtab %}

{% tab title="Unity" %}
Not yet supported in Unity. Reach out to our team to request this feature.
{% endtab %}

{% tab title="React Native" %}
Not yet supported in React Native. Reach out to our team to request this feature.
{% endtab %}
{% endtabs %}

Passing `false` assigns the user to the control group, preventing the SDK from making any decisions, as `shouldUpsell` will always be `true` then. Passing `true` allows the SDK to utilize the machine learning model to optimize conversions, provided that a model has already been deployed to the designated flow.

{% hint style="warning" %}
Even when using `setDecisionsEnabled`, it’s important to keep all the context capturing and logging fully operational for both cohorts (control and treatment) as this is critical to train the ML models.

The SDK initialization via `ContextManager.applicationDidFinishLaunchingWithOption` and other configurations should **also** remain unchanged.
{% endhint %}

#### Step 2: Send Us Your Cohort Information

In order to correctly analyze your data you should send us details about your A/B test cohorts. We provide a dedicated API for this:

{% tabs %}
{% tab title="iOS" %}
First, configure a default AB test assignment in your `Configuration`:

```swift
let config = Configuration(
    defaultABTestInformation: ABTestInformation(
        testName: "none", 
        cohortName: "control"
    )
)
ContextManager.applicationDidFinishLaunchingWithOptions(
    launchOptions, 
    licenseKey: "your_license_key", 
    configuration: config
)
```

Then, when your app determines the user's cohort assignment, call:

```swift
// For users in the treatment group
ContextManager.setABTestInformation(testName: "context_sdk", cohortName: "treatment")

// For users in the control group
ContextManager.setABTestInformation(testName: "context_sdk", cohortName: "control")
```

{% hint style="info" %}
The new `setABTestInformation` method replaces the previous approach using custom signals and provides better analytics tracking.
{% endhint %}
{% endtab %}

{% tab title="Android" %}
{% tabs %}
{% tab title="Kotlin" %}

```kotlin
ContextSDK.globalCustomSignals["ab_test_name"] = "none"
// OR
ContextSDK.globalCustomSignals["ab_test_name"] = "context_sdk"

ContextSDK.globalCustomSignals["ab_test_cohort"] = "control"
// OR
ContextSDK.globalCustomSignals["ab_test_cohort"] = "treatment"
```

{% endtab %}

{% tab title="Java" %}

```java
ContextSDK.Companion.getGlobalCustomSignals().set("ab_test_name", "none");
// OR
ContextSDK.Companion.getGlobalCustomSignals().set("ab_test_name", "context_sdk");

ContextSDK.Companion.getGlobalCustomSignals().set("ab_test_cohort", "control");
// OR
ContextSDK.Companion.getGlobalCustomSignals().set("ab_test_cohort", "treatment");
```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Flutter" %}

```dart
_contextSdkPlugin.setGlobalCustomSignals({
  'ab_test_name': 'none',
  // OR
  // 'ab_test_name': 'context_sdk',
});

_contextSdkPlugin.setGlobalCustomSignals({
  'ab_test_cohort': 'control',
  // OR
  // 'ab_test_cohort': 'treatment',
});
```

{% endtab %}

{% tab title="Unity" %}

```csharp
ContextSDKBinding.SetGlobalCustomSignal("ab_test_name", "none");
// OR
ContextSDKBinding.SetGlobalCustomSignal("ab_test_name", "context_sdk");

ContextSDKBinding.SetGlobalCustomSignal("ab_test_cohort", "control");
// OR
ContextSDKBinding.SetGlobalCustomSignal("ab_test_cohort", "treatment");
```

{% endtab %}

{% tab title="React Native" %}

```javascript
setGlobalCustomSignals({ ab_test_name: 'none' });
// OR
setGlobalCustomSignals({ ab_test_name: 'context_sdk' });

setGlobalCustomSignals({ ab_test_cohort: 'control' });
// OR
setGlobalCustomSignals({ ab_test_cohort: 'treatment' });
```

{% endtab %}
{% endtabs %}

#### Step 3: Inform Us Of The Segmentation Split

Since your app controls the split, we request that you inform our team of the initial split percentage and notify us of any planned changes, as this impacts our reporting.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.contextsdk.com/context-decision/advanced/custom-ab-test-segmentation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
