# A/B tests

Label each page with the variant of a test it showed, and the dashboard compares the variants side by side.

One attribute on the tag, naming the variant a page showed, gives each variant its own conversion rate, bounce rate, speed and errors, from the visits fivebar already counts. Your site or testing tool decides who sees which variant, and fivebar counts what each one did, for a test of one change or of several at once.

## Tagging the variant

Give the tag a [custom property](https://fiveb.ar/docs/properties.md) named after the test, with the variant as its value:

```
<script async data-domain="example.com" data-property-test-hero="b"
  src="https://fiveb.ar/js/tally.js"></script>
```

Write it into every page a visitor in the test sees, not only the page being tested. A visit and its conversions are counted under the properties of the page it started on, so someone who lands on a blog post without the property and then signs up on the tested page counts under neither variant.

The script reads its tag once, as it loads, so the variant has to be on the tag by then. That’s simplest when your server, or an edge function, picks the variant and writes it into the page. A testing tool that picks in the browser has to add fivebar’s tag itself, once it has picked:

```
var tag = document.createElement('script');
tag.async = true;
tag.setAttribute('data-domain', 'example.com');
tag.setAttribute('data-property-test-hero', variant);
tag.src = 'https://fiveb.ar/js/tally.js';
document.head.appendChild(tag);
```

Keeping a visitor in the same variant from one visit to the next is your testing tool’s job, as fivebar sets no cookies and remembers nobody. The variant’s name is all fivebar needs, so never put the tool’s ID for a visitor in a value.

## Reading the result

Once pages send the property, it has a pane of its own under Properties, headed Test hero. Click your goal in the Goals pane, and that pane counts each variant’s conversions with its conversion rate: the visits that started on the variant and reached the goal, as a share of all the visits that started on it.

Compare visits and conversion rates rather than visitors, who are counted once a day each, so someone who comes back on another day counts again. fivebar gives each variant’s rate, not whether the difference between them is more than chance. For a significance calculator, filter by each variant and read its Visits, then add the goal and read its Conversions. An app [connected to fivebar](https://fiveb.ar/docs/mcp.md) reads the same figures, so you can ask it which variant did better.

Set the dates to the days the test ran, and the address keeps them, to share the result or come back to it: see [Linking to a range](https://fiveb.ar/docs/date-ranges.md#linking-to-a-range).

## More than conversions

Click a variant in its pane to filter the whole dashboard by it. The tiles give its visits’ bounce rate and visit duration, and the filter goes with you to the [Speed](https://fiveb.ar/docs/speed.md) and [Errors](https://fiveb.ar/docs/error-pages.md) pages, so you can see whether a variant is slower or breaks more often before you choose it.

## Testing several changes at once

For a multivariate test, give each change a property of its own:

```
data-property-test-hero="b" data-property-test-price="annual"
```

Filter by the goal and by hero b, and the Test price pane gives each price’s conversion rate alongside hero b. Or put the whole combination in one property’s value, as `data-property-test="hero-b price-annual"`, and its pane ranks every combination together.

A tag counts up to 8 properties, so a site’s tests share them with its other properties. See [Names and values](https://fiveb.ar/docs/properties.md#names-and-values) for the rest.

## Ending a test

Take the property off the tag when the test ends. What it counted stays, on the days it ran. Give the next test a name of its own, such as `test-hero-2`, so a range covering both never mixes their variants.
