PHPackages                             rasuvaeff/yii3-ab-testing-clickhouse - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rasuvaeff/yii3-ab-testing-clickhouse

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rasuvaeff/yii3-ab-testing-clickhouse
====================================

ClickHouse exposure and conversion trackers for Yii3 A/B testing

v1.0.1(1mo ago)00BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jun 12Pushed 1w agoCompare

[ Source](https://github.com/rasuvaeff/yii3-ab-testing-clickhouse)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-ab-testing-clickhouse)[ Docs](https://github.com/rasuvaeff/yii3-ab-testing-clickhouse)[ RSS](/packages/rasuvaeff-yii3-ab-testing-clickhouse/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (32)Versions (5)Used By (0)

rasuvaeff/yii3-ab-testing-clickhouse
====================================

[](#rasuvaeffyii3-ab-testing-clickhouse)

[![Stable Version](https://camo.githubusercontent.com/ee18a7801dc0ba79ddea10d13e64b2014cd4ad2cbd9c50af4a8c21638ca138dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/rasuvaeff/yii3-ab-testing-clickhouse)[![Total Downloads](https://camo.githubusercontent.com/8a0dcb35517c83126d16c83dcfedf12aa69eed6984274679c05f2e2377a711b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652e737667)](https://packagist.org/packages/rasuvaeff/yii3-ab-testing-clickhouse)[![Build](https://camo.githubusercontent.com/20beebfe74744d16c46570e69f7a43e2d237b3431fac3824bdc78fe807c33c76/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652f6275696c642e796d6c3f6272616e63683d6d6173746572)](https://github.com/rasuvaeff/yii3-ab-testing-clickhouse/actions)[![Static Analysis](https://camo.githubusercontent.com/4e02605e7371e63db65f5947fdbd9ebc163dbe030b63c490c785c588d997c61f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d6173746572266c6162656c3d737461746963253230616e616c79736973)](https://github.com/rasuvaeff/yii3-ab-testing-clickhouse/actions)[![PHP](https://camo.githubusercontent.com/013555a7206d242967b126438315baef33b78798a87097402f2f65bd05fb02db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652f706870)](https://packagist.org/packages/rasuvaeff/yii3-ab-testing-clickhouse)[![License](https://camo.githubusercontent.com/7a286b034e40bb5f5f5917eb0dda1694403eb01db0ac4a865108d6285ce489af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7261737576616566662f796969332d61622d74657374696e672d636c69636b686f7573652e737667)](LICENSE.md)[Русская версия](README.ru.md)

ClickHouse exposure and conversion trackers for Yii3 A/B testing. Implements the `ExposureTracker` and `ConversionTracker` interfaces from `rasuvaeff/yii3-ab-testing`, buffering events in memory and writing them to ClickHouse in batches.

> Using an AI coding assistant? [llms.txt](llms.txt) contains a compact API reference you can ingest in your prompt context.

Requirements
------------

[](#requirements)

- PHP 8.3+
- `rasuvaeff/yii3-ab-testing` ^1.2
- `rasuvaeff/clickhouse-toolkit` ^1.1
- a PSR-18 HTTP client (for example `guzzlehttp/guzzle`) for the ClickHouse connection

Installation
------------

[](#installation)

```
composer require rasuvaeff/yii3-ab-testing-clickhouse
```

With Yii3 config-plugin this package binds `ExposureTracker`, `ConversionTracker`and `ClickHouseTrackingFlushMiddleware` automatically. Do not bind the tracker interfaces from another adapter at the same time or `yiisoft/config` reports a `Duplicate key` error. To send events to several sinks, compose them with the core `CompositeExposureTracker` / `CompositeConversionTracker`.

The DI factory pulls a `Rasuvaeff\ClickHouseToolkit\ClickHouseClientFactory`from the container and uses it to build the batch writers. Bind the factory in your application:

```
use Rasuvaeff\ClickHouseToolkit\ClickHouseClientFactory;
use Rasuvaeff\ClickHouseToolkit\ClickHouseConfig;

return [
    ClickHouseClientFactory::class => static fn (): ClickHouseClientFactory => new ClickHouseClientFactory(
        new ClickHouseConfig(host: getenv('CLICKHOUSE_HOST') ?: '127.0.0.1', /* ... */),
    ),
];
```

Database schema
---------------

[](#database-schema)

DDL for the two event tables ships under `migrations/` as ClickHouse `*.sql`files, applied by the toolkit's `ClickHouseMigrationRunner`:

```
use Rasuvaeff\ClickHouseToolkit\ClickHouseMigrationRunner;

(new ClickHouseMigrationRunner(
    $clickHouseClient,
    __DIR__ . '/vendor/rasuvaeff/yii3-ab-testing-clickhouse/migrations',
))->run();
```

TableColumns`ab_exposures``experiment, variant, subject_id, is_forced, is_fallback, is_sticky, environment, ts``ab_conversions``experiment, variant, subject_id, goal, is_forced, is_fallback, is_sticky, environment, ts`Both are `MergeTree` partitioned by `toYYYYMM(ts)`; `ts` defaults to `now()`.

Usage
-----

[](#usage)

```
use Rasuvaeff\ClickHouseToolkit\ClickHouseBatchWriter;
use Rasuvaeff\Yii3AbTesting\AbTesting;
use Rasuvaeff\Yii3AbTestingClickHouse\ClickHouseConversionTracker;
use Rasuvaeff\Yii3AbTestingClickHouse\ClickHouseExposureTracker;

$exposure = new ClickHouseExposureTracker(
    writer: new ClickHouseBatchWriter($client, 'ab_exposures', ClickHouseExposureTracker::COLUMNS),
);
$conversion = new ClickHouseConversionTracker(
    writer: new ClickHouseBatchWriter($client, 'ab_conversions', ClickHouseConversionTracker::COLUMNS),
);

$ab = new AbTesting(
    provider: $provider,
    strategy: $strategy,
    exposureTracker: $exposure,
    conversionTracker: $conversion,
);

$assignment = $ab->assign(experiment: 'checkout-button', subjectId: (string) $userId);
$ab->trackExposure($assignment);            // buffered, not sent yet
$ab->trackConversion($assignment, goal: 'purchase');
```

### Request-end flushing

[](#request-end-flushing)

Tracking never makes a network call on `trackExposure()` or `trackConversion()`. Rows are appended to an in-memory buffer and written on `flush()`. The package ships `ClickHouseTrackingFlushMiddleware` for the recommended request-end flush:

```
use Rasuvaeff\Yii3AbTestingClickHouse\ClickHouseTrackingFlushMiddleware;

return [
    ClickHouseTrackingFlushMiddleware::class,
    // place it late in the PSR-15 pipeline
];
```

The middleware wraps the downstream handler in `try/finally`, flushes both trackers after the request, and swallows/logs flush failures so analytics never breaks the user response.

If you do not use a PSR-15 pipeline, call `flush()` yourself once at request end or from `register_shutdown_function()`.

API reference
-------------

[](#api-reference)

ClassDescription`ClickHouseExposureTracker`Buffers exposures; `flush()` batch-writes to `ab_exposures``ClickHouseConversionTracker`Buffers conversions (with `goal`); `flush()` batch-writes to `ab_conversions``ClickHouseTrackingFlushMiddleware`PSR-15 middleware that flushes both trackers safely at request endSecurity
--------

[](#security)

- Connection credentials travel via the toolkit's `ClickHouseClientFactory`(headers / config from env), never in URLs. The toolkit validates table and column identifiers and uses parameterized inserts.
- `subject_id` is stored verbatim and may be personally identifiable. Apply TTL / partition retention per your privacy policy.
- Middleware swallows flush failures by design, so add logging/monitoring for the warning message if analytics delivery matters operationally.

Examples
--------

[](#examples)

See [examples/](examples/) for a runnable script (no server required — uses an in-memory writer).

Development
-----------

[](#development)

```
composer build          # full gate: validate + normalize + cs + psalm + test
composer cs:fix         # auto-fix code style
composer psalm          # static analysis
composer test           # run unit tests (integration tests skipped without CLICKHOUSE_HOST)
```

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

2

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (13 commits)")

---

Tags

ab-testinganalyticsbatch-processingclickhouseevent-trackingphpyii3trackingclickhouseanalyticsyii3experimentab-testing

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-ab-testing-clickhouse/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-ab-testing-clickhouse/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-ab-testing-clickhouse)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M108](/packages/mcp-sdk)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.2k](/packages/typo3-cms-core)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.8k11](/packages/sunrise-http-router)[xima/xima-typo3-frontend-edit

Frontend Edit - This extension provides an edit button for editors within frontend content elements.

1414.3k](/packages/xima-xima-typo3-frontend-edit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
