> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create variations with custom code

> Use an AI assistant prompt to set up variations with custom JavaScript and CSS.

A test of a page change needs one variation for each version, and each variation needs code that makes its change. Building that by hand means creating the experiment, adding each version, and entering the code for each one in turn. Your AI assistant can do all of that from one request, writing the code from your description and reading it back so you can confirm Kameleoon stored it. The result is a draft with every variation's code in place, and each selector must match an element on the live page, so check the draft before you start it.

## How the variation tools fit into your workflow

* **Create the experiment:** Your AI assistant creates a draft code-based experiment with a first variation, adds a second variation, and stores the code for each one.
* **Add a variation:** Your AI assistant adds a variation to an experiment that already exists.
* **Set the traffic split:** Your AI assistant sets how much traffic each version gets on a draft, paused, or scheduled experiment.

## Before you begin

* **Setup:** Connect Kameleoon to your AI assistant. For a chat assistant such as Claude or ChatGPT, see [Connect Kameleoon to Claude and ChatGPT](https://docs.kameleoon.com/mcp/connect-ai-assistants.md). For a coding agent such as Claude Code, Codex, or Cursor, see [Set up MCP clients](https://docs.kameleoon.com/mcp/set-up-clients.md).
* **Site code:** Have the code of the site you're testing ready. Enter it in the Site code field of any prompt on this page. The field starts with the placeholder `{{SITECODE}}`, and every other prompt updates to match.

## Create a code-based experiment with variations

Use this prompt to have your AI assistant create a [code-based experiment](https://docs.kameleoon.com/user-manual/experimentation/web-experimentation/code-based-experiments/using-the-code-editor.md) with two variations. Each variation runs the JavaScript and CSS that you describe.

Enter your site code in the Site code field, then replace the page URL and the selectors with your own values. Your AI assistant writes the code from your description, so each selector must match an element on the live page.

When the request works, Kameleoon has a draft experiment with Variation 1 and Variation 2, and your AI assistant shows the stored code for each one. Check that each selector and change matches your description before you start the experiment.

While the experiment is a draft, Kameleoon splits traffic evenly, so each of the three versions gets about 33% of the traffic. To set a different split before you start, see [Prepare a draft experiment](https://docs.kameleoon.com/mcp/prepare-draft-experiment.md).

## Add and update variations

A variation added to a running experiment starts with 0% of the traffic, so it receives no visitors until you change its share.

Both variation tools check the experiment first. On an experiment that isn't a draft, such as one that's running, the tool returns a preview of what will change and applies it only after you confirm.

> [!WARNING]
>
> Updating a variation's code replaces the code stored in Kameleoon. Before you update it, pull the current code with `experiment_code_get`, and keep a copy.

### Add a variation with a prompt

Use this prompt to add a variation named Variation 3 to an experiment that already exists. The prompt has your AI assistant save the current code of every variation first.

When the request works, the experiment has a new variation named Variation 3, and your AI assistant returns the current code of the existing variations so that you can keep a copy.

If the experiment isn't a draft, your AI assistant returns a preview and adds the variation only after you confirm.

## Set the traffic split

The traffic split decides how much of the traffic each version of an experiment gets. Your AI assistant can set the split of a draft, paused, or scheduled experiment. A draft's split changes immediately. The new split of a paused or scheduled experiment takes effect when it starts or resumes. For a running experiment, change the split in the Kameleoon app.

### Set the split for a draft, paused, or scheduled experiment

Use this prompt to set the traffic split of a draft, paused, or scheduled experiment, so that the original page and each of its three variations get 25% of the traffic.

When the request works on a paused or scheduled experiment, your AI assistant returns a preview of the change and applies the new split only after you confirm. On a draft, it applies the new split right away.

If the experiment is running, deviated, or stopped, your AI assistant can't change its split. Use the Kameleoon app instead.

Tool parameters are in the [Experiment tools](https://docs.kameleoon.com/mcp/tools-experiments.md) reference.
