Laravel A/B Testing and Feature Flag Package

Admin   Laravel   603  2022-07-19 06:30:02

The Laravel A/B Test package helps you quickly set up A/B tests and feature flags in a Laravel app. The package uses the self-hosted ABRouter service (which also has paid hosted options) to power the A/B and feature flag settings.

Here's an example controller using this package to A/B test UI features, in this case, a button color:

1use Abrouter\Client\Client;
3class ExampleController
5 public function __invoke(Client $client)
6 {
7 $userId = auth()->user()->id;
8 $buttonColor = $client->experiments()->run($userId, 'button_color');
9 return view('button', [
10 'color' => $buttonColor->getBranchId(),
11 ]);
12 }

Another useful feature is feature flags, which help you roll experimental/new features out to customers incrementally, toggling on/off without a code redeploy:

1$isEnabledButton = $client->featureFlags()
2 ->run('enabled_button_feature_flag');
4view('featureFlags', [
5 'enabledButtonFeatureFlag' => $isEnabledButton,

You'll need to set up the ABRouter service to use this package. You can learn more about this service from the ABRouter Docs. You can learn about this package, get full installation instructions, and view the source code on GitHub.