Skip to main content

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.

  1. 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).

  2. 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 getStringAssignment returns variations. It will return the defaultValue if the environment is not enabled.

note

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: undefined

The time when the subject was assigned to the variation. Example: "2021-06-22T17:35:12.000Z"

featureFlagstringDefault: undefined

An Eppo feature flag key. Example: "recommendation-algo"

allocationstringDefault: undefined

An Eppo allocation key. Example: "allocation-17"

experimentstringDefault: undefined

An Eppo experiment key. Example: "recommendation-algo-allocation-17"

subjectstringDefault: undefined

An 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: undefined

The 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()
]);
}
}
note

More details about logging and examples can be found in the event logging page.

Debugging

[Placeholder: Need PHP-specific debugging methods and examples]