Stateless, deterministic assignment
sha256(salt:subjectId) picks the bucket. Same salt and subject, same variant — on every server, with no storage. The algorithm is a versioned public contract.
Five packages around one contract — deterministic assignment, event schema v2, and two delivery paths that write identical rows.
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
}// 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();SELECT variant, uniqExact(subject_id) AS subjects
FROM ab_exposures_v2 FINAL
WHERE experiment = 'checkout-button'
AND decision_reason = 'assigned'
GROUP BY variant| Package | Layer | What it adds |
|---|---|---|
| yii3-ab-testing | Assignment, tracking | The facade, hash bucketing v1, targeting, events v2, attribution rules, PSR-3 sinks |
| yii3-ab-testing-db | Definitions, persistence | Runtime-editable experiments with revisions, a console control plane, DbAssignmentStore |
| yii3-ab-testing-web | Identity, persistence | Anonymous subject id cookie, consent, signed-cookie sticky store, signed receipts |
| yii3-ab-testing-outbox | Delivery | Durable exposure and conversion trackers on the transactional outbox |
| yii3-ab-testing-clickhouse | Analytics | The schema v2 tables both delivery paths write into, plus their migrations |