> For the complete documentation index, see [llms.txt](https://docs.spara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.spara.com/agents/channels/configuring/a-b-testing.md).

# A/B Testing

Spara lets you test multiple versions of a channel side by side to measure which performs better before rolling out changes to all your traffic. This helps you iterate on your sales conversations with confidence, without risking your funnel performance.

<figure><img src="/files/CWhoZbXbjgO3IEXxFfAR" alt=""><figcaption><p>The A/B Tests tab: add variants to a trigger group and split traffic between them.</p></figcaption></figure>

## What can be tested

Anything unique to a channel can be tested, including:

* **AI instructions** (prompt): Test different conversational styles, objection handling, or qualification approaches
* **Preview messages**: Test different pop-up messages to see which drives more engagement
* **Suggested responses**: Test different suggested reply buttons
* **Media and calendars**: Test whether showing a video or calendar at different points improves conversion

Since each variant has its own configuration, you can test any combination of these variables.

## How variants are grouped

A/B tests are organized by **trigger**, the condition that activates a channel. Variants that share a trigger split that trigger's traffic between them:

* [Chat](/agents/channels/chat.md) variants share a URL trigger (the `when` condition that decides when the channel activates).
* [Phone](/agents/channels/phone.md) and [SMS](/agents/channels/sms.md) variants share a phone number.

This means creating a variant is as simple as duplicating a channel: the variant inherits the original's trigger automatically and joins the same test group.

## How to set up an A/B test

A/B tests are managed through the **Experiments** panel on a channel's **Overview** tab. No setup from the Spara team is required.

### Create a variant

1. Open the channel you want to test from the [**Agents**](https://app.spara.co/agents) page.
2. In the **Experiments** panel, click **Create variant**. The variant inherits the control's trigger automatically.
3. Configure the variant's prompt, preview message, suggested responses, media, or calendar, whatever you're testing.
4. Use the **breadcrumb switcher** at the top of any channel in the experiment to jump between the control and all variants. Each shows a **Published** or **Draft** badge so you can see what's live at a glance.

### Set the traffic split

In the **Experiments** panel, adjust the traffic percentage for each variant. The control receives whatever traffic isn't allocated to variants. Traffic is split deterministically, so the same visitor always sees the same variant.

### Manage variants

* **Archive** a variant to stop it receiving traffic without deleting it. Archived variants can be restored later.
* **Promote** a variant to control if it outperforms the original. The promoted variant takes over the control role and the former control becomes a variant.
* Each channel's **Overview** tab shows its current role (control, variant, or archived), its inherited trigger, and its share of traffic.

### How traffic splitting works

Spara deterministically assigns each visitor to a variant using a hash of the visitor's unique identifier. This means:

* The same visitor always sees the same variant (no mid-conversation switching)
* The split is random and evenly distributed
* You control the percentages using the traffic controls in the Experiments panel

### Assigning leads to groups

To track which group each lead was in, configure each variant to assign a field value when it activates. For example:

* Control assigns `experiment_group = "control"`
* Variant assigns `experiment_group = "experiment"`

This field persists on the lead record, so you can filter analytics and exports by group even after the experiment ends.

## Measuring results

Use the [Analytics](/platform/analytics.md) page to compare performance between variants. Use the **Agent** filter to view metrics for each variant individually, then compare:

* **Leads engaged**: Which variant drives more conversations?
* **Calls scheduled**: Which variant converts more leads to meetings?
* **Emails collected**: Which variant captures more contact information?
* **Conversation length**: Are leads more or less engaged with each variant?

### How long to run a test

Run your test until you have enough data to be confident in the results. As a general guideline, aim for at least 100 engaged leads per variant before drawing conclusions. High-traffic sites may reach significance in days; lower-traffic sites may need several weeks.

## Using third-party analytics tools

{% hint style="warning" %}
Spara does not natively integrate with third-party A/B testing tools. The approach below describes a custom integration using Spara's APIs.
{% endhint %}

You can use Spara's [Web API](/developers/spara-api/web-api.md) or [Javascript API](/developers/spara-api/javascript-api.md) to connect an external experimentation platform (e.g., Amplitude, LaunchDarkly) with Spara's routing:

1. Set up your experiment in the third-party tool, assigning visitors to groups
2. Use the Spara Javascript API to set a field on each visitor (e.g., `experiment_group = "control"`)
3. Configure your channels to activate based on that field value

{% hint style="info" %}
Do not switch a visitor's channel mid-conversation. Only assign the experiment group before the first interaction.
{% endhint %}

## Loading Spara for only some visitors

To show Spara to only a percentage of website visitors, you can conditionally load the embed snippet:

```javascript
<script>
var SPARA_TRAFFIC_PERCENTAGE = 10; // 10 = 10%, 100 = always show

(function() {
  var k = 'spara_traffic', d = 30;
  var s = localStorage.getItem(k);
  var run = SPARA_TRAFFIC_PERCENTAGE >= 100 || (s ? JSON.parse(s).i && Date.now() < JSON.parse(s).e : Math.random() * 100 < SPARA_TRAFFIC_PERCENTAGE);

  if (!s || Date.now() > JSON.parse(s).e) {
    localStorage.setItem(k, JSON.stringify({i: run, e: Date.now() + d * 864e5}));
  }

  if (run) {
    var script = document.createElement('script');
    script.src = 'https://app.spara.co/embed-<app_id>.js';
    document.head.appendChild(script);
  }
})();
</script>
```

Set `SPARA_TRAFFIC_PERCENTAGE` to control the percentage. The assignment persists for 30 days so returning visitors stay in the same group.

{% hint style="info" %}
It is usually simpler to load Spara for 100% of visitors and use the variant-based A/B testing approach instead. Configure a "control" that shows only the avatar (no preview message) and a variant that shows a pop-up. This achieves the same result without needing to modify your embed code.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.spara.com/agents/channels/configuring/a-b-testing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
