dmt-software / ab-middleware
ab testing middleware compatible with psr
0.0.5
2024-11-05 14:45 UTC
Requires
- php: ^8.3
- dflydev/fig-cookies: ^3.1
- google/analytics-admin: ^0.24.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- ext-pcov: *
- guzzlehttp/psr7: ^2.7
- phpunit/phpunit: ^11.4
- squizlabs/php_codesniffer: ^3.10
- twig/twig: ^3.14
Suggests
- twig/twig: If you want to use the twig helper
README
This PSR-15 middleware allows you to do A/B testing on your application.
Cookies are used to keep track of a randomly generated user-id. Based on this cookie, a variant is selected for an experiment.
The Twig helper can be used to conditionally render the experiment template variants.
Although more than one experiment can be defined, only one experiment is supposed to be active at a time.
Installation
composer require dmt-software/ab-middleware
Usage
use DMT\AbMiddleware\AbService; use DMT\AbMiddleware\AbPsrMiddleware; // define your experiments $experiments = [ 'active-experiment' => [ 'variant-1' => 0.3, 'variant-2' => 0.3, 'control' => 0.4, ], 'old-experiment' => [ 'variant-1' => 0.3, 'variant-2' => 0.3, 'control' => 0.4, ], ]; // instantiate the service $service = new AbService($experiments); // instantiate the middleware $abMiddleware = new AbPsrMiddleware($service, 'ab-uid-cookie-name'); // add the middleware to your middleware stack