diff --git a/docs/abtesting.md b/docs/abtesting.md index 083041e..c8f7c07 100644 --- a/docs/abtesting.md +++ b/docs/abtesting.md @@ -9,9 +9,9 @@ The logic of the implement follows this logic: * A node can be configured to enable A/B Test. You also define a code to set the name of the test * When Murph receives a request, an event is dispatched and contains an `App\Core\Ab\AbTestInterface` object * You must create an event subscriber and set variations defined by - * a name (a string) - * a value (whatever you want) - * a percentage chance (optional) + - a name (a string) + - a value (whatever you want) + - a percentage chance (optional) * Then a variation is picked and saved in user cookies * Finally, you can retrieve the picked variation PHP side and template side @@ -90,3 +90,50 @@ public function foo(AbContainerInterface $testContainer) {# ... #} {% endif %} ``` + +## Global A/B Test + +If you need to perform an A/B test everywhere, you need to create a specific listener: + +``` +// src/EventListener/CustomAbListener.php + +namespace App\EventListener; + +use App\Core\EventListener\AbListener as EventListener; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; + +class CustomAbListener extends EventListener +{ + /** + * {@inheritdoc} + */ + protected function supports(Request $request): bool + { + return true; + } + + /** + * {@inheritdoc} + */ + protected function getAbTestCode(): string + { + return 'my_global_ab_test_code'; + } +} +``` + +`CustomAbListener` must be registred: + +``` +# config/services.yml + +services: + # ... + + App\EventListener\CustomAbListener; + tags: + - { name: kernel.event_listener, event: kernel.request } + - { name: kernel.event_listener, event: kernel.response } +```