Assignments
Assignments are the mechanism through which a given Subject is assigned to a variation for a feature flag, experiment, or bandit.
Currently, the Eppo PHP SDK supports the following assignment types:
- String
- Boolean
- JSON
- Numeric
String Assignments
String assignments return a string value that is set as the variation for the experiment. String flags are the most common type of flags.
$subjectAttributes = [];
$variation = $eppoClient->getStringAssignment(
'subject-1',
'experiment_5',
$subjectAttributes
);
if ($variation === 'control') {
// do something
}
Typed Assignments
Additional functions are available for different value types:
getBooleanAssignment(...)
getNumericAssignment(...)
getIntegerAssignment(...)
getStringAssignment(...)
getJSONAssignment(...)
[Placeholder: Need specific PHP examples for each typed assignment]
Handling Empty Assignments
The SDK requires a defaultValue when computing assignments. This value is returned if the subject is not matched to any allocation or if the SDK encounters an error.
-
The Traffic Exposure setting on experiments/allocations determines the percentage of subjects the SDK will assign to that experiment/allocation. For example, if Traffic Exposure is 25%, the SDK will assign a variation for 25% of subjects and
""for the remaining 75% (unless the subject is part of an allow list). -
Assignments occur within the environments of feature flags. You must enable the environment corresponding to the feature flag's allocation in the user interface before
getStringAssignmentreturns variations. It will return thedefaultValueif the environment is not enabled.
It may take up to 10 seconds for changes to Eppo experiments to be reflected by the SDK assignments.
Assignment Logger Schema
The SDK will invoke the logAssignment function with the following parameters:
timestampstringDefault: undefinedThe time when the subject was assigned to the variation. Example: "2021-06-22T17:35:12.000Z"
featureFlagstringDefault: undefinedAn Eppo feature flag key. Example: "recommendation-algo"
allocationstringDefault: undefinedAn Eppo allocation key. Example: "allocation-17"
experimentstringDefault: undefinedAn Eppo experiment key. Example: "recommendation-algo-allocation-17"
subjectstringDefault: undefinedAn identifier of the subject or user assigned to the experiment variation. Example: UUID
subjectAttributesarrayDefault: []A free-form map of metadata about the subject. These attributes are only logged if passed to the SDK assignment function. Example: { "country": "US" }
variationstringDefault: undefinedThe experiment variation the subject was assigned to. Example: "control"
Logging Examples
To use the Eppo SDK for experiments that require analysis, pass in an implementation of the LoggerInterface to the init function on SDK initialization. The SDK invokes the callback to capture assignment data whenever a variation is assigned. The assignment data is needed in the warehouse to perform analysis.
The code below illustrates an example implementation of a logging callback using Segment, but you can use any system you'd like. The only requirement is that the SDK receives a logAssignment callback function. Here we define an implementation of the Eppo AssignmentLogger interface containing a single function named logAssignment:
<?php
use Eppo\Logger\LoggerInterface;
use Eppo\Logger\AssignmentEvent;
use Eppo\Logger\LoggerInterface;
class SegmentLogger implements LoggerInterface
{
public function logAssignment(AssignmentEvent $assignmentEvent): void
{
Segment::track([
'event' => 'Flag Assignment for ' . $assignmentEvent->featureFlag,
'userId' => $assignmentEvent->subject,
'properties' => $assignmentEvent->toArray()
]);
}
}
More details about logging and examples can be found in the assignment logging page.