-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd3e655
Showing
7 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Rene Bartkowiak <info@rene-bartkowiak.com> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Bart\Ab; | ||
|
||
use Namshi\AB\Container; | ||
use Namshi\AB\Test; | ||
|
||
class Ab | ||
{ | ||
private $tests = []; | ||
private $default = null; | ||
|
||
public function __construct() | ||
{ | ||
if (!session('ab_seed')) { | ||
session(['ab_seed' => 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Bart\Ab; | ||
|
||
class Facade extends \Illuminate\Support\Facades\Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'ab'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Bart\Ab; | ||
|
||
use Illuminate\Support\Facades\Blade; | ||
|
||
class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([__DIR__.'/config/ab.php' => config_path('ab.php')]); | ||
|
||
Blade::directive('test', function($expression) | ||
{ | ||
return "<?php if({$expression} === app('ab')->getCurrentTest()): ?>"; | ||
}); | ||
|
||
Blade::directive('endtest', function() | ||
{ | ||
return '<?php endif; ?>'; | ||
}); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->singleton(Ab::class, function () { | ||
return new Ab(); | ||
}); | ||
|
||
$this->app->alias(Ab::class, 'ab'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'enabled' => true, | ||
'default' => 'none', | ||
|
||
'tests' => [ | ||
'teaser1' => 1, | ||
'teaser2' => 2, | ||
'teaser3' => 1, | ||
], | ||
|
||
]; |