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 SDK supports the following assignment types:
- String
- Boolean
- JSON
- Numeric
- Integer
Depending on the values you pass to the getAssignment()
function, the SDK will return different results based on whether the subject details match the assignment rules you set in the Eppo UI.
This section will cover the different types of assignments that you can make with the Eppo SDK.
String Assignments
String assignment return a string value that is set as the variation for the experiment. String flags are the most common type of flags. They are useful for both A/B/n tests and advanced targeting use cases.
import * as EppoSdk from "@eppo/react-native-sdk";
const client = EppoSdk.getInstance();
const flagKey = "flag-key-123";
const subjectKey = getUserId() || "user-123";
const defaultAssignment = "version-a";
const subjectAttributes = {
"country": "US",
"age": 30,
"isReturningUser": true
};
const variant = client.getStringAssignment(
flagKey,
subjectKey,
subjectAttributes,
defaultAssignment
);
// Use the variant value to determine which component to render
if (variant === "version-a") {
return <versionAComponent />
} else if (variant === "version-b") {
return <versionBComponent />
}
Boolean Assignments
Boolean flags support simple on/off toggles. They're useful for simple, binary feature switches like blue/green deployments or enabling/disabling a new feature.
import * as EppoSdk from "@eppo/react-native-sdk";
const client = EppoSdk.getInstance();
const flagKey = "flag-key-123";
const subjectKey = getUserId() || "user-123";
const defaultAssignment = false;
const subjectAttributes = {
"country": "US",
"age": 30,
"isReturningUser": true
};
const variant = client.getBooleanAssignment(
flagKey,
subjectKey,
subjectAttributes,
defaultAssignment
);
// Use the variant value to determine which component to render
if (variant) {
return <FeatureEnabledComponent />
} else {
return <FeatureDisabledComponent />
}