orchid/experiment

1.1 2019-03-18 09:17 UTC

README

68747470733a2f2f7472617669732d63692e6f72672f6f7263686964736f6674776172652f6578706572696d656e742e7376673f6272616e63683d6d6173746572 68747470733a2f2f7374796c6563692e696f2f7265706f732f3135393733303034332f736869656c643f6272616e63683d6d6173746572 68747470733a2f2f636f6465636f762e696f2f67682f6f7263686964736f6674776172652f6578706572696d656e742f6272616e63682f6d61737465722f67726170682f62616467652e737667 68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f6578706572696d656e742f762f737461626c65 68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f6578706572696d656e742f646f776e6c6f616473 68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f6578706572696d656e742f6c6963656e7365 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636861742d74656c656772616d2d626c75652e737667

An A/B Testing suite for Laravel which allows multiple experiments.

Installation

Download using Composer:

$ composer require orchid/experiment

Base Usage

Your cache driver will be used by default.

$experiment = new Experiment();

// Distribution
$ab = $experiment->start([
    'A' => 1,
    'B' => 1,
]); // A or B

The experiment is transmitted in the form of an array, where the keys are the names, and the values are the required ratios. For example, if you specify two values containing A -> 50 and B -> 100, then first there will be 50 users with the value A, then there will be 100 users with the value B. This allows us to clearly define how the testing will be distributed.

$storage = Cache::store('redis');
$experiment = new Experiment('my-key',$storage);

$ab = $experiment->start([
    'A' => 50,
    'B' => 100,
]); // A or B

You can also install via your request:

http:://example.com?my-key=A

Cookie

I recommend putting this on an middleware and immediately install a cookie using

namespace App\Http\Middleware;

use Closure;
use Orchid\Experiment\Experiment;

class Experiments
{
    
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     *
     * @return mixed
     * @throws \Exception
     */
    public function handle($request, Closure $next)
    {
        $experiment = new Experiment('AB');

        $experiment->startAndSaveCookie([
            'A' => 50,
            'B' => 50,
        ]);
        
        return $next($request);
    }
}

This allows you to transfer data to Google analytics and similar services using javascript

alert( document.cookie );

Laravel encrypts all cookies by default, so do not forget to specify your key in the exceptions app/Http/Middleware/EncryptCookies.php:

namespace App\Http\Middleware;

use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;

class EncryptCookies extends Middleware
{
    /**
     * The names of the cookies that should not be encrypted.
     *
     * @var array
     */
    protected $except = [
        'AB'
    ];
}

Tests

php vendor/bin/phpunit --coverage-html ./logs/coverage ./tests

Donate & Support

If you would like to support development by making a donation you can do so here. 😊

License

The MIT License (MIT). Please see License File for more information.

orchid.software  ·  GitHub @tabuna  ·  Twitter @orchid_platform