PHP Experiments is an A/B Test and Split Test library
Code Status
, (*1)
Introduction
PHP Experiments is built for A/B and Split Testing for Matomo Analytics but can be used in any
PHP project. Matomo (formerly Piwik) is the leading open source web analytics platform used on over 1 million
websites and apps in over 150 countries. InnoCraft is the company of the makers of Matomo Analytics., (*2)
Features
- Easily create and run A/B tests and split tests.
- Experiment traffic allocation: For example configure that only 80% of all users should participate in an experiment.
- Variation traffic allocation: For example allocate more traffic to some specific variations, giving other variations less traffic.
- When a user enters an experiment for the first time, a variation will be chosen randomly. On all subsequent requests the same variation will be activated.
- Possibility to force a specific variation instead of choosing it randomly.
- To ensure a user always gets to see the same variation, the name of the activated variation is stored in a cookie, a custom storage can be configured.
- Easy to use with plain arrays and easily extensible and customizable (custom storage, filters and variations can be defined).
- Tested with unit tests.
- No dependencies, lightweight, simple.
Example
See examples directory for various examples., (*3)
Running an A/B test might be as easy as:, (*4)
$variations = [['name' => 'green'], ['name' => 'blue']];
$experiment = new Experiment('experimentName', $variations);
$activated = $experiment->getActivatedVariation();
echo $activated->getName();
Running a split URL test can be as easy as:, (*5)
$variations = [
['name' => 'layout1', 'url' => '/layout1'],
['name' => 'layout2', 'url' => '/layout2']
];
$experiment = new Experiment('experimentName', $variations);
$activated = $experiment->getActivatedVariation();
// redirects to either URL or does nothing if the original version was activated
$activated->run();
Requirements
Installation
To get the latest version, require the library using Composer:, (*6)
$ composer require innocraft/php-experiments
Instead, you may manually update your require block and run composer update
if you so choose:, (*7)
{
"require": {
"innocraft/php-experiments": "^1.0"
}
}
License
PHP Experiments is released under the LGPL v3 license, see LICENSE., (*8)
Developer
Docs generation
To update the documentation within the docs directory execute the following commands, (*9)
cd docs
-
composer install
(only needed once)
./generateDocs.sh