abrouter/laravel-abtest 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

abrouter/laravel-abtest

Composer 安装命令:

composer require abrouter/laravel-abtest

包简介

AbrLaravelClient :construction_worker_woman: is a PHP client for laravel to run ab-tests via ABRouter.

README 文档

README

ABRouter AB Test 👷‍♀️ is a simple package for base library to run A/B tests via ABRouter (open-source) with Laravel. You can find base PHP library in https://github.com/abrouter/abrouter-php-client

You're welcome to visit the docs.

Learn how to deploy ABRouter on your server.

What is the ABRouter service ?

ABRouter is the open-source product to manage experiments(A/B split tests). The service provides easy to manage dashboard to keep experiments under control. You can create experiments, branches and set up a percentage for every branch. Then, when you're running an ab-test on PHP you will receive a perfect branch-wise response that following the rules, that you set up.

Providing feature flags(feature toggles) Available for free and open-source.

You can find the ABRouter product source code by the following link: https://github.com/abrouter/compose

Features

🛠 A/B Tests

🛠 Feature flags

🛠 Built-in statistics

🛠 Incredible UI to manage it

🛠 Parallel running (non-blocking A/B tests running)

Prepare your first A/B test

Besides of the installing this package you need to have an account on ABRouter. Your token and experiment id will be also there. Feel free to read step by step instruction Impelementing A/B tests on Laravel

📦 Install

Via composer

$ composer require abrouter/laravel-abtest

Setting service provider

This package provide auto discovery for service provider

If Laravel package auto-discovery is disabled, add service providers manually to /config/app.php. There are service provider you must add:

\Abrouter\LaravelClient\Providers\AbrouterServiceProvider::class

Publish client configuration:

php artisan vendor:publish --tag=abrouter

Configure ABRouter client:

Put your ABRouter token in /config/abrouter.php. You can find this token in ABRouter dashboard.

use Abrouter\LaravelClient\Bridge\KvStorage;
use Abrouter\LaravelClient\Bridge\ParallelRunning\TaskManager;

return [
    'token' => '14da89de1713a74c1ed50aafaff18c24bf372a9913e67e6a7a915def3332a97c9c9ecbe2cd6d3047',
    'host' => 'https://abrouter.com',
    'parallelRunning' => [
        'enabled' => true, //parallel running, enabled by default. See next section.
        'taskManager' => TaskManager::class,
    ],
    'kvStorage' => KvStorage::class
];

Configure Parallel running

Parallel running is a feature that allows you to run A/B tests asynchronously. It requires ready-to-use Laravel cache (probably by Redis).

This feature enables caching of experiment branches to run the experiment locally, then using Laravel built-in queues to sync the data with ABRouter server. Please make sure, your supervisor config, queues and caching storage is enabled in Laravel to use.

Parallel running allows to run your A/B tests without blocking. Additionally, you can configure it on your own.

🚀 Running A/B tests

use Abrouter\Client\Client;

class ExampleController
{
    public function __invoke(Client $client)
    {
        $userId = auth()->user()->id;
        $buttonColor = $client->experiments()->run($userId, 'button_color');
        return view('button', [
            'color' => $buttonColor->getBranchId(),
        ]);
    }
}

🚀 Running feature flags

use Abrouter\Client\Client;

class ExampleController
{
    public function __invoke(Client $client)
    {
        $isEnabledButton = $client->featureFlags()->run('enabled_button_feature_flag');

        return view('featureFlags', [
            'enabledButtonFeatureFlag' => $isEnabledButton,
        ]);
    }
}

🚀 Sending the stats

use Abrouter\Client\Client;
use Abrouter\Client\Builders\StatEventBuilder;

class ExampleController
{
    public function __invoke(Client $client, StatEventBuilder $statEventBuilder)
    {
        $userId = auth()->user()->id;
        //sending button_click event as button_click+1
        $client->statistics()->sendEvent(
            $eventBuilder
                ->incremental()
                ->event('button_click')
                ->setUserId($userId)
                ->build()
        );
        
        //sending purchase event with purchase amount (+30)
        $client->statistics()->sendEvent(
            $eventBuilder
                ->summarize()
                ->event('purchase')
                ->setValue(30)
                ->setUserId($userId)
                ->build()
        );
    }
}

For additional details of sending events please see StatEventBuilder class.

Managing UI

You can create an experiment/feature flags and set up statistics and get your token and id of experiment on ABRouter or just read the docs.

Example

You can get an dockerized usage example by the following link: (https://github.com/abrouter/laravel-example)

🔧 Contributing

Please feel free to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PSR-2.

📄 License

GPL3. Please see License File for more information.

abrouter/laravel-abtest 适用场景与选型建议

abrouter/laravel-abtest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.02k 次下载、GitHub Stars 达 108, 最近一次更新时间为 2021 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 abrouter/laravel-abtest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 abrouter/laravel-abtest 我们能提供哪些服务?
定制开发 / 二次开发

基于 abrouter/laravel-abtest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 23.02k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 108
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 108
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2021-11-02