https://github.com/dmt-software/ab-middleware
PSR-15 ab testing middleware
https://github.com/dmt-software/ab-middleware
ab-testing psr-15
Last synced: 3 months ago
JSON representation
PSR-15 ab testing middleware
- Host: GitHub
- URL: https://github.com/dmt-software/ab-middleware
- Owner: dmt-software
- License: mit
- Created: 2024-10-25T19:12:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-15T12:08:39.000Z (6 months ago)
- Last Synced: 2025-10-26T00:47:11.051Z (6 months ago)
- Topics: ab-testing, psr-15
- Language: PHP
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PSR-15 ab testing middleware
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
```bash
composer require dmt-software/ab-middleware
```
## Usage
```php
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
```