Sticky, weighted A/B testing for Statamic entries with explicit conversion tracking and a Control Panel results dashboard.
Requirements
- PHP 8.3 or later
- Statamic 6
Installation
composer require frank-l93/ab-testingphp artisan migrate
The addon registers automatically through Composer package discovery.
Creating an experiment
Create ordinary fields in the blueprint for the content you want to test and for its variants. The control and variant content must use the same field type (for example, both use Bard, text, textarea, or an asset field).
For example, to test a headline field, add a headline_variants grid with
id, weight, and headline fields. Each variant needs a unique ID and a
positive weight.
Render the experiment with explicit tag parameters:
{{ ab_testing:entry key="homepage-headline-2026" field="headline" variants="headline_variants" control_weight="50" variant_field="headline"}} <h1>{{ headline }}</h1>{{ /ab_testing:entry }}
field selects the control field. variants selects the grid. variant_field
selects the grid column containing the alternative value. The grid identifiers
default to id and weight, but can also be renamed with variant_id and
variant_weight.
The visitor is assigned once and remains on the selected variant for 30 days.
Existing convention
The original experiment_content, ab_test_key, ab_test_control_weight, and
ab_test_variants fields remain supported. They are only a convention, not an
addon requirement. The current project templates can continue to use them.
Recording a conversion
Conversions are explicit: place this tag on the goal or thank-you page that
represents success. Its experiment value must exactly match the experiment
key used when rendering the variant:
{{ ab_testing:conversion experiment="homepage-headline-2026" }}
It sends a CSRF-protected conversion beacon. A visitor can convert once per
experiment. Results are stored in the ab_test_results table.
Viewing results
Control Panel users can open Tools -> A/B Tests to review each experiment's total and per-variant impressions, conversions, conversion rate, and last activity.
Static caching
Do not fully statically cache pages that use ab_testing:entry. Assignment
requires a request so that the visitor's cookie can be read and written.
Development
composer installvendor/bin/phpunit
Contributing
Please open an issue before submitting a substantial change. Pull requests should include focused tests for behavioral changes.
License
This project is open-sourced under the MIT license.