Skip to content
YII3-AB-TESTING(3)rasuvaeff PHP Library ManualYII3-AB-TESTING(3)

NAME ​

yii3-ab-testing — deterministic, stateless A/B testing for Yii3 with explicit exposure tracking

SYNOPSIS ​

$ composer require rasuvaeff/yii3-ab-testing

$assignment = $ab->assign(experiment: 'checkout-button', subjectId: (string) $userId); if ($assignment->isVariant('green')) {    // Show green button.} // assign() does NOT auto-track. Call explicitly:$exposure = $ab->trackExposure($assignment);$ab->trackConversion($assignment, goal: 'purchase', exposure: $exposure);

DESCRIPTION ​

Deterministic, stateless A/B testing for Yii3 with explicit exposure tracking.

Re-resolving an assignment later can return a different variant than the visitor saw. This package gives stable hash-based assignment, decision reasons, and receipts for later conversions.

  • The same salt and subjectId always give the same variant (WeightedHashAssignmentStrategy).
  • Weighted variants, and a forced variant for QA validated against an allow-list.
  • Every Assignment carries a reason (assigned, forced, fallback_*) and a source (computed, store).
  • assign() is pure. trackExposure() and trackConversion() are explicit and return events.
  • AssignmentReceipt links a conversion to the original exposure in a later request.
  • Targeting rules, with a fallback variant on mismatch.
  • Sticky variants through AssignmentStore; ConfigurationAwareAssignmentStore drops stale pins when weights change.
  • Logger sinks, composite and deduplicating trackers; a reset hook for RoadRunner and Swoole.

EXAMPLES ​

Attributes a later conversion to the variant the visitor actually saw, using an assignment receipt.

$receipt = $exposure->receipt();$_SESSION['ab_receipt'] = $receipt->toArray();  // or a signed cookie // … a later request … $receipt = AssignmentReceipt::fromArray($_SESSION['ab_receipt']);$ab->trackConversionForReceipt($receipt, goal: 'purchase', context: $context);

Allow-lists which context attributes reach analytics, with renaming and redaction.

new AllowListAnalyticsContextPolicy(    allowedAttributes: ['country', 'plan', 'user'],    renamedAttributes: ['country' => 'geo'],stored column name    redactedAttributes: ['user'],kept as a column, value masked);

Wraps a tracker so the same exposure is emitted at most once per request.

$tracker = new DeduplicatingExposureTracker(tracker: $realExposureTracker);$tracker->trackExposure($exposureEvent);$tracker->trackExposure($exposureEvent);suppressed in this request

SEE ALSO ​

PackageRole
yii3-ab-testing-db(3)DB provider and sticky store
yii3-ab-testing-web(3)Cookie sticky store, SubjectIdMiddleware
yii3-ab-testing-outbox(3)Durable delivery of events
yii3-ab-testing-clickhouse(3)ClickHouse analytics schema and migrations

BUGS ​

Changing weights or the variant set shifts bucket boundaries and reshuffles some subjects. Only a new salt freezes a cohort. Needs 64-bit PHP.

DEPENDENCIES

required by: yii3-ab-testing-clickhouse(3), yii3-ab-testing-db(3), yii3-ab-testing-outbox(3), yii3-ab-testing-web(3)

HISTORY

First released as v1.0.0 on 2026-06-10; 14 releases in all.

v2.1.12026-09-02
v2.1.02026-08-23
v2.0.02026-08-01
v1.6.02026-07-31
v1.5.22026-07-29
v1.5.12026-07-25
v1.5.02026-07-24
v1.4.22026-06-30
v1.4.12026-06-27
v1.4.02026-06-20

… and 4 earlier. All releases

rasuvaeff/yii3-ab-testing 2.1.1mutation gate 99%used by 4 packagesYII3-AB-TESTING(3)

/ search · n N next, previous · g G top, bottom · q back to the index