diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a1d11b5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Rene Bartkowiak + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5fb80b --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +Laravel A/B Testing +=================== +AB is a server-side A/B testing tool for Laravel applications and provides a pretty simple feature set that is a great free alternative to services like Optimizely. It allows you to experiment with different variations of your website while test selection will be handled automatically. + +Installation +------------ +Install using composer: + + composer require bart/ab + +Add the service provider to `app/config/app.php`: + + Bart\Ab\ServiceProvider::class, + +Register the AB alias: + + 'AB' => Bart\Ab\Facade::class, + +Configuration +------------- + +Publish the included configuration file like this: + + php artisan vendor:publish --provider="Bart\Ab\ServiceProvider" + +Next, edit the `config/packages/bart/ab/config.php` file. The following configuration options are available: + + +### Enabled +Enables or disbales the A/B testing. + + 'enabled' => true + + +### Default +If A/B testing is disbaled, `AB::getCurrentTest()` will return this. + + 'default' => 'none' + + +### Tests +An array of test identifiers with an assigned level of distibution. + + 'tests' => [ + 'teaser1' => 1, + 'teaser2' => 2, + 'teaser3' => 1, + ] + +The above (default) configuration will display teaser version 2 to 50% of your users, whereas version 1 and 3 will be displayed to 25% of your users each. + + +Usage +----- +After you have defined your tests and enabled testing in the config you can start designing your A/B tests. It's as easy as 1-2-3 because the only thing you need to do is displaying a different peace of content for each test. Let's assume you have defined the tests from above, your view could look like this: + + @test('teaser1') + Teaser 1 is being displayed + @endtest + + @test('teaser2') + Teaser 2 is being displayed + @endtest + + @test('teaser3') + Teaser 3 is being displayed + @endtest + + +### Tracking +This package doesn't handle any goal or conversion tracking because every company is approaching this in a slightly different way. We would suggest to use a custom Google Analytics dimension and pass the assigned test version in your master view: + + dataLayer.push({'version': '{{ AB::getCurrentTest() }}'}); + + +Contribution and questions +------- +If you have any questions or suggestions please feel free to ask or create megre request. Happy testing! \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a101d7c --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "bart/ab", + "description": "A/B testing tool for Laravel apps", + "keywords": ["laravel","optimizely","ab","split","testing"], + "homepage": "https://github.com/bart/ab", + "license": "MIT", + "authors": [ + { + "name": "Rene Bartkowiak", + "email": "info@rene-bartkowiak.com" + } + ], + "minimum-stability": "dev", + "require": { + "php": ">=5.4.0", + "illuminate/support": "^5.0", + "namshi/ab": "^1.1" + }, + "autoload": { + "psr-4": { + "Bart\\Ab\\": "src/" + } + } +} diff --git a/src/Ab.php b/src/Ab.php new file mode 100644 index 0000000..41338f7 --- /dev/null +++ b/src/Ab.php @@ -0,0 +1,38 @@ + mt_rand()]); + } + + $this->tests = new Container([new Test('tests', $this->getTestsFromConfig())], session('ab_seed')); + $this->default = config('ab.default', 'none'); + } + + public function getCurrentTest() { + if (!$this->isEnabled()) { + return $this->default; + } + + return $this->tests['tests']->getVariation(); + } + + private function getTestsFromConfig() { + return config('ab.tests', []); + } + + private function isEnabled() { + return config('ab.enabled', false); + } +} diff --git a/src/Facade.php b/src/Facade.php new file mode 100644 index 0000000..3058556 --- /dev/null +++ b/src/Facade.php @@ -0,0 +1,11 @@ +publishes([__DIR__.'/config/ab.php' => config_path('ab.php')]); + + Blade::directive('test', function($expression) + { + return "getCurrentTest()): ?>"; + }); + + Blade::directive('endtest', function() + { + return ''; + }); + } + + /** + * Register the application services. + * + * @return void + */ + public function register() + { + $this->app->singleton(Ab::class, function () { + return new Ab(); + }); + + $this->app->alias(Ab::class, 'ab'); + } +} diff --git a/src/config/ab.php b/src/config/ab.php new file mode 100644 index 0000000..b3d84c7 --- /dev/null +++ b/src/config/ab.php @@ -0,0 +1,14 @@ + true, + 'default' => 'none', + + 'tests' => [ + 'teaser1' => 1, + 'teaser2' => 2, + 'teaser3' => 1, + ], + +];