thoughtco / statamic-ab-tester
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:statamic-addon
Requires
- statamic/cms: ^5.0
Requires (Dev)
- orchestra/testbench: ^7.0 || ^8.0
- pestphp/pest: ^2.35
This package is auto-updated.
Last update: 2024-11-16 10:09:47 UTC
README
Installation
composer require thoughtco/statamic-ab-tester
Usage
Experiment types
There are two types of experiments you can run:
Entry
An Entry experiment lets you select an entry and display its content on the page. This can be selected from any collection and will be available as an entry
variable inside the ab
tag.
Manual
A Manual experiment lets you determine what you want to do inside the experiment, e.g. show a different nav UI, show a different button style. You can use the autogenerated variant:id
or use variant:label
to determine what to show to the user.
Tags
This package provides tags that you can use in your Statamic templates:
ab
This tag sets an A/B test for the given handle. It will randomly choose a experiment variant, record a hit and provide the experiment and handle to the content of the tag.
If you want your variant to persist over the session lifetime, set session="true"
{{ ab experiment="experiment_handle" session="true" }} {{ experiment }} {{ variant }} {{ /ab }}
ab:success
This tag marks an A/B test as successful.
{{ ab:success experiment="experiment_handle" variant="variant_handle" }}
or if you've used session="true" on the ab tag:
{{ ab:success experiment="experiment_handle" from_session="true" }}
ab:failure
This tag marks an A/B test as a failure.
{{ ab:failure experiment="experiment_handle" variant="variant_handle" }}
or if you've used session="true" on the ab tag:
{{ ab:failure experiment="experiment_handle" from_session="true" }}
Facade
This package provides a facade for interacting with experiments:
\Thoughtco\StatamicABTester\Experiment
get an experiment
$experiment = \Thoughtco\StatamicABTester\Experiment::find('experiment_handle');
get all experiments
\Thoughtco\StatamicABTester\Experiment::all();
query experiments
\Thoughtco\StatamicABTester\Experiment::query()->where('handle', 'test')->get();
Experiment
Once you have an experiment you can record hits, successes, failures and get results.
hit
Mark an experiment as being viewed:
$experiment->recordHit($variantHandle);
success
Mark an experiment as being successful:
$experiment->recordSuccess($variantHandle);
failure
Mark an experiment as being a failure:
$experiment->recordFailure($variantHandle);
results
Get the results of an experiment:
$experiment->results();