Skip to content

Yii3 A/B TestingExperiments you can reproduce, rows you can trust.

Five packages around one contract — deterministic assignment, event schema v2, and two delivery paths that write identical rows.

Yii3 A/B Testing logo

Three calls ​

php
use Rasuvaeff\Yii3AbTesting\AbTesting;
use Rasuvaeff\Yii3AbTesting\ConfigExperimentProvider;
use Rasuvaeff\Yii3AbTesting\WeightedHashAssignmentStrategy;

$ab = new AbTesting(
    provider: new ConfigExperimentProvider(config: [
        'checkout-button' => [
            'enabled' => true,
            'salt' => 'checkout-v1',
            'fallbackVariant' => 'control',
            'variants' => ['control' => 50, 'green' => 50],
        ],
    ]),
    strategy: new WeightedHashAssignmentStrategy(),
);

$assignment = $ab->assign(experiment: 'checkout-button', subjectId: $userId);

if ($assignment->isVariant('green')) {
    // render the green button
}
php
// assign() never tracks. Record the exposure when the variant is shown...
$exposure = $ab->trackExposure($assignment);

// ...and the conversion when the goal happens, linked to that exposure.
$ab->trackConversion($assignment, goal: 'purchase', exposure: $exposure);

// Converting in a later request? Carry the receipt instead of re-assigning.
$_SESSION['ab_receipt'] = $exposure->receipt()->toArray();
sql
SELECT variant, uniqExact(subject_id) AS subjects
FROM ab_exposures_v2 FINAL
WHERE experiment = 'checkout-button'
  AND decision_reason = 'assigned'
GROUP BY variant

The family ​

PackageLayerWhat it adds
yii3-ab-testingAssignment, trackingThe facade, hash bucketing v1, targeting, events v2, attribution rules, PSR-3 sinks
yii3-ab-testing-dbDefinitions, persistenceRuntime-editable experiments with revisions, a console control plane, DbAssignmentStore
yii3-ab-testing-webIdentity, persistenceAnonymous subject id cookie, consent, signed-cookie sticky store, signed receipts
yii3-ab-testing-outboxDeliveryDurable exposure and conversion trackers on the transactional outbox
yii3-ab-testing-clickhouseAnalyticsThe schema v2 tables both delivery paths write into, plus their migrations