Skip to content

PHP Experiments is a library that lets you run A/B and split tests

License

Notifications You must be signed in to change notification settings

innocraft/php-experiments

Repository files navigation

PHP Experiments is an A/B Test and Split Test library

Code Status

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

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.

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.

Running an A/B test might be as easy as:

$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:

$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

  • PHP 5.5.9 or greater

Installation

To get the latest version, require the library using Composer:

$ composer require innocraft/php-experiments

Instead, you may manually update your require block and run composer update if you so choose:

{
    "require": {
        "innocraft/php-experiments": "^1.0"
    }
}

License

PHP Experiments is released under the LGPL v3 license, see LICENSE.

Developer

Docs generation

To update the documentation within the docs directory execute the following commands

  • cd docs
  • composer install (only needed once)
  • ./generateDocs.sh

About

PHP Experiments is a library that lets you run A/B and split tests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages