Is Feature Enabled
This topic describes the Is Feature Enabled method, which determines whether a feature is enabled for a given user.
Determines whether a feature is enabled for a given user. The purpose of this method is to allow you to separate the process of developing and deploying features from the decision to turn on a feature. Build your feature and deploy it to your application behind this flag, then turn the feature on or off for specific users.
Version
SDK v3.0 and higher
Description
This method traverses the client's datafile and checks the feature flag for the feature key that you specify.
- Analyzes the user's attributes.
- Hashes the userID.
The method then evaluates the feature rollout for a user. The method checks whether the rollout is enabled, whether the user qualifies for the audience targeting, and then randomly assigns either on
or off
based on the appropriate traffic allocation. If the feature rollout is on for a qualified user, the method returns true
.
Parameters
The table below lists the required and optional parameters in Java.
Parameter | Type | Description |
---|---|---|
featureKey required | string | The key of the feature to check. The feature key is defined from the Features dashboard. |
userId required | string | The ID of the user to check. |
attributes optional | map | A map of custom key-value string pairs specifying attributes for the user that are used for audience targeting. Non-string values are only supported in the 3.0 SDK and above. |
Returns
True if the feature is enabled. False if the feature is disabled or not found.
Examples
This section shows a simple example of how you can use the IsFeatureEnabled
method.
The Java example shows 3.0-specific functionality of passing in non-string attributes.
// Evaluate a feature flag and a variable
Boolean enabled = optimizelyClient.isFeatureEnabled("price_filter", userId, attributes);
Integer min_price = optimizelyClient.getFeatureVariableInteger("price_filter", "min_price", userId, attributes);
Exceptions
SDK | Exception | Meaning |
---|---|---|
Java | N/A | Does not throw an exception if the given feature key is unknown. |
Source files
The language/platform source files containing the implementation for Java is Optimizely.java.
Updated over 2 years ago