AbTesting
Rasuvaeff\Yii3AbTesting\AbTesting
Class · rasuvaeff/yii3-ab-testing · Source · implements AssignmentResolver
Entry point: resolves subjects into variants and turns those decisions into analytics events.
Event identity, timestamp and the context allow-list are applied here, once, so every delivery path serializes the same fields. Sinks receive a finished event and only transport it.
assign() and is() remain free of side effects — exposure stays an explicit act, because auto-tracking would invent impressions on prefetch, on hidden branches and on repeated calls.
Constructor
new AbTesting(
ExperimentProvider $provider,
AssignmentStrategy $strategy,
ExposureTracker $exposureTracker = new NullExposureTracker(),
ConversionTracker $conversionTracker = new NullConversionTracker(),
Psr\Clock\ClockInterface $clock = new SystemClock(),
EventIdGenerator $eventIds = new Uuid7EventIdGenerator(),
AnalyticsContextPolicy $contextPolicy = new AllowListAnalyticsContextPolicy(),
)Methods
assign()
assign(
string $experiment,
string $subjectId,
?string $forcedVariant = null,
?AssignmentContext $context = null,
): Assignmentresolve()
resolve(
string $experiment,
string $subjectId,
?string $forcedVariant = null,
?AssignmentContext $context = null,
): Assignmentis()
is(
string $experiment,
string $variant,
string $subjectId,
?string $forcedVariant = null,
): boolisWithContext()
isWithContext(
string $experiment,
string $variant,
string $subjectId,
AssignmentContext $context,
?string $forcedVariant = null,
): booltrackExposure()
trackExposure(Assignment $assignment): ExposureEventRecords that the subject saw the variant.
Returns the event so the caller can keep its identity — typically as $event->receipt() stored in a cookie or session, to attribute a conversion that happens in a later request.
trackConversion()
trackConversion(
Assignment $assignment,
string $goal,
?ExposureEvent $exposure = null,
): ConversionEventRecords a conversion for an assignment resolved in this request.
Pass $exposure when the exposure happened in the same request, so the conversion is attributed to it exactly instead of by attribution window.
trackConversionForReceipt()
trackConversionForReceipt(
AssignmentReceipt $receipt,
string $goal,
?AssignmentContext $context = null,
): ConversionEventRecords a conversion for an exposure from an earlier request.
The receipt carries the decision as it was, so a reweight or a salt change between the two requests cannot silently re-attribute the conversion to a different variant. $context describes the conversion request, not the original exposure.
getRegistry()
getRegistry(): ExperimentRegistry