A/B tests and experiments
VeritaMetrics records which version of a page each visitor saw and what they did next. Your own code splits the traffic. This works for a test of two versions, a test of many versions, and a bandit test that sends more visitors to the version that is doing better.
1. Record which version rendered
When the page renders a version, send one event that names the experiment and the version. The names are yours to choose; keep them short and stable.
window.verita('trackEvent', 'experiment_view', { experiment: 'home-hero', variant: 'B' }); The event is sent within about two seconds of the call, while the page is open. It does not wait for the visitor to leave, so a tab closed on a phone does not lose it.
2. Name the outcome, and tag it with the version
An outcome is the thing you want more of: a click on the call-to-action, a signup, a form submission. Autocapture names a button by its visible text, so a test that changes the text splits one button into two rows. Give the element a key instead. The key stays the same in every version, and the version rides along as a property:
<a href="/signup"
data-verita-event-name="hero_cta"
data-verita-prop-variant="B">
Run a free audit
</a>
Every click now arrives as hero_cta with variant: "B". See
Autocapture for how keys and properties
work.
3. Optional: record whether it was seen
A version below the fold only gets a chance if visitors scroll to it. Add
data-verita-expose to the element and the page reports whether it reached the
screen, so you can divide outcomes by the visitors who saw it. The tracker sends an
element_seen event the first time the element is seen, while the page is open, so
that count does not depend on how the visit ends. The fuller element_exposure
report is sent when the visitor leaves the page, so it undercounts on browsers that send
nothing at that moment. See
exposure tracking.
The exposure event carries only the key you give it, so put the version in the key:
<section data-verita-expose="pricing-table-b">
...
</section> How the two events fit together
experiment_view counts how many page loads got each version. That is the
denominator. The outcome event (hero_cta above) counts what visitors did on each
version. That is the numerator. Both carry variant, so each version has a count of
views and a count of outcomes, and the rate is one divided by the other.
Both values must come from one variable. If the script that sends the view and the markup that tags the button pick a version separately, they can disagree and the rate means nothing.
---
const variant = Math.random() < 0.5 ? 'A' : 'B';
---
<a href="/signup" data-verita-event-name="hero_cta" data-verita-prop-variant={variant}>
{variant === 'A' ? 'Start your audit' : 'Run a free audit'}
</a>
<script define:vars={{ variant }}>
window.verita('trackEvent', 'experiment_view', { experiment: 'home-hero', variant });
</script> The counts in the event details panel are events, so a visitor who clicks twice counts twice. An outcome on a different page, such as a signup completed later, carries the version only if your code sends it on that event too, which means keeping the visitor's version in your own storage (see the stored choice below).
Choosing the version
VeritaMetrics does not assign versions. Three common ways, each with a cost:
- Random on each page load, in the browser. It needs no storage. A visitor who loads the page twice can see both versions, which matters little when most visits are a single page.
- Random on the server, when the page is built. The same trade-off, and the visitor never sees one version flash into the other.
- A stored choice. A cookie or browser storage keeps each visitor on one version. The tracker sets no cookies, so this storage belongs to your site and to the rules that apply to you.
Reading the results
-
Open Top Events and click the
experiment_viewrow. The event details panel lists each property with its most common values, so you see how many page loads got each version. -
Click your outcome row (
hero_cta). The same panel shows how many outcomes carried each version. - Divide the outcomes by the views for each version. That is the rate to compare.
To pivot the whole dashboard on the version, register variant as a definition (see
Custom events and definitions). To use the outcome as a
conversion, make it a goal (see Goals and data export).
Events can also be exported, so you can analyse a test elsewhere.
Bandit tests
A bandit is a rule in your own code that sends a larger share of visitors to the version with
the better results so far. The records are the same: your code picks the version, sends
experiment_view, and the outcomes carry the version. One difference matters when you
read the numbers. The share of visitors per version changes over time, so compare rates
(outcomes divided by views) and never raw totals.
How much traffic a test needs
A common rule of thumb for each version, at 80% power and a 5% significance level, is
16 × (1 − p) ÷ (p × lift²) visitors, where p is the outcome rate and
lift is the relative change you want to detect. With a 10% outcome rate and a 20%
relative lift, that is 16 × 0.9 ÷ (0.1 × 0.04) = 3,600 visitors per version. A rarer outcome
needs far more, and a small site can only detect a large change.
Decide the number before the test starts. Checking the results every day and stopping at the first good-looking gap raises the chance of a false win. A test planned for sequential checking uses different stopping rules.
What VeritaMetrics does not do here
- It does not assign visitors to versions.
- It does not calculate significance or declare a winner.
- It does not change your page.
It records what your code sends and what visitors do, with no cookies and no personal data.
Explore the documentation
Jump to another guide.