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.

Assignment Types

The Eppo SDK supports the following assignment types:

  • String
  • Boolean
  • JSON
  • Integer
  • Double

String Assignments

String assignments are the most common type. They return a string value that is set as the variation for the experiment.

String assignedVariation = eppoClient.getStringAssignment(
"flagkey",
"subjectKey",
"defaultValue"
);

Boolean Assignments

Boolean flags support simple on/off toggles:

Boolean isEnabled = eppoClient.getBooleanAssignment(
"flagkey",
"subjectKey",
false
);

JSON Assignments

JSON assignments are useful for complex configuration values:

JsonNode config = eppoClient.getJSONAssignment(
"flagkey",
"subjectKey",
defaultJsonNode
);

If you prefer to use a different JSON library, you can use getJSONStringAssignment() to get the unparsed JSON string.

Numeric Assignments

For numeric values, you can use either integer or double assignments:

Integer count = eppoClient.getIntegerAssignment(
"flagkey",
"subjectKey",
0
);

Double price = eppoClient.getDoubleAssignment(
"flagkey",
"subjectKey",
0.0
);

Subject Attributes

All assignment methods support optional subject attributes that can be used for targeting:

Attributes subjectAttributes = new Attributes(
Map.of(
"country", EppoValue.valueOf("FR"),
"age", EppoValue.valueOf(60),
"isReturningUser", EppoValue.valueOf(true)
)
);

String assignedVariation = eppoClient.getStringAssignment(
"flagkey",
"subjectKey",
subjectAttributes,
"defaultValue"
);

Assignment Logger

For experiments, you'll need to implement an assignment logger to track exposure events. The logger receives an assignment object with the following fields:

timestampDateDefault: undefined

The time when the subject was assigned to the variation

experimentStringDefault: undefined

The key of the experiment

featureFlagStringDefault: undefined

The key of the feature flag

allocationStringDefault: undefined

The key of the allocation

variationStringDefault: undefined

The identifier of the assigned variation

subjectStringDefault: undefined

The identifier of the subject

subjectAttributesAttributesDefault: {}

A map of metadata about the subject

info

More details about logging and examples (with Segment, Rudderstack, mParticle, and Snowplow) can be found in the event logging page.