Determines whether a feature test or rollout is enabled for a given user, and sends an impression event if the user is bucketed into a feature test using the feature. No impression event is sent if the user is bucketed into a rollout.
Note: a feature test takes priority over the rollout.
The purpose of this method is 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 by running tests and rollouts.
This method takes into account any user attributes
passed in, to determine if the user is part of the audience that qualifies for the experiment.
Version
SDK v2.1
Description
This method traverses the client's datafile and evaluates all the feature tests running for the user. This evaluation works exactly like Activate for A/B tests, as follows:
- Qualifies the user for audience targeting by analyzing the user's attributes.
- Hashes the Identify users or bucketing ID to apply traffic allocation.
- Respects whitelisting and forced bucketing.
- Triggers an impression event if the user qualifies for the experiment.
If the user qualifies for a variation, this method returns theenabled
setting for that variation.
If the user does not qualify for any feature tests, 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
.
Parameter definitions
This section provides general information about the required and optional parameters.
For the specific parameter name in one of Optimizely's supported languages, see Parameter names.
Parameter | Type | Description |
---|---|---|
feature key required | string | The key of the feature to check. The feature key is defined from the Features dashboard. For more information, see: Use feature flags. |
user ID required | string | The ID of the user to check. For more information, see: Identify users. |
attributes optional | map | A map of custom key-value string pairs specifying attributes for the user. For more information, see: Define audiences and attributes. |
Parameter names
This section shows the specific parameter names for each supported language.
featureKey
userId
attributes
experimentKey
userId
userAttributes
featureKey
userId
attributes
featureKey
userId
attributes
featureKey
userId
attributes
featureKey
userId
attributes
featureFlagKey
userId
attributes
feature_key
user_id
attributes
feature_flag_key
user_id
attributes
featureKey
userId
attributes
Returns
The value this method returns is determined by your feature tests and feature rollouts. The example shows the specific value returned for each supported language.
@return True if the feature is enabled. False if the feature is disabled or not found.
<returns>True if feature is enabled, false or null otherwise</returns>
@return True if the feature is enabled. False if the feature is disabled or not found.
@return {boolean} True if the feature is enabled for the user, false otherwise
@return {boolean} True if the feature is enabled for the user, false otherwise
@return YES if feature is enabled, false otherwise.
@return boolean
Returns: True if the feature is enabled for the user. False otherwise.
@return [True] if the feature is enabled.
@return [False] if the feature is disabled.
@return [False] if the feature is not found.
@return YES if feature is enabled, false otherwise.
Note
If you're running a feature test, this method does not return the variation assigned to a user. Instead, it returns
true
orfalse
, depending on that variation's setting.
Examples
This section shows simple examples of how you can use the method.
using OptimizelySDK;
var optimizelyClient = new Optimizely(datafile);
string userId = "";
// Evaluate a feature flag and a variable
bool enabled = optimizelyClient.IsFeatureEnabled("price_filter", userId);
int? min_price = optimizelyClient.GetFeatureVariableInteger("price_filter", variableKey: "min_price", userId: userId);
// Evaluate a feature flag and a variable
Boolean enabled = optimizelyClient.isFeatureEnabled("price_filter", userId);
Integer min_price = optimizelyClient.getFeatureVariableInteger("price_filter", "min_price", userId);
// Evaluate a feature flag and a variable
var enabled = optimizelyClientInstance.isFeatureEnabled('price_filter', userId);
var min_price = optimizelyClientInstance.getFeatureVariableInteger('price_filter', 'min_price', userId);
// Evaluate a feature flag and a variable
bool enabled = [client isFeatureEnabled:@"price_filter" userId: userId];
int min_price = [[client getFeatureVariableInteger:@"price_filter" userId: userId] integerValue];
// Evaluate a feature flag and a variable
$enabled = $optimizelyClient->isFeatureEnabled('price_filter', $userId);
$min_price = $optimizelyClient->getFeatureVariableInteger('price_filter', 'min_price', $userId);
# Evaluate a feature flag and variable
enabled = optimizely_client.is_feature_enabled('price_filter', user_id)
min_price = optimizely_client.get_feature_variable_integer('price_filter', 'min_price', user_id)
# Evaluate a feature flag and a variable
enabled = optimizely_client.is_feature_enabled('price_filter', user_id)
min_price = optimizely_client.get_feature_variable_integer('price_filter', 'min_price', user_id)
// Evaluate a feature flag and a variable
let enabled = optimizelyClient?.isFeatureEnabled("price_filter", userId: userId)
let min_price = optimizelyClient?.getFeatureVariableInteger("price_filter", "min_price", userId: userId)?.integerValue
Exceptions
SDK | Exception | Meaning |
---|---|---|
Java | NA | Does not throw an exception if the given feature key is unknown. |
See also
See all the topics in the Feature Management section, especially Use feature flags and Run feature tests.
Side effects
The table lists other Optimizely functionality that may be triggered by using this method.
Functionality | Description |
---|---|
Impressions | Accessing this method triggers an impression if the user is included in a feature test. It doesn't trigger an impression if the user is in a rollout or if neither a test nor rollout is active. |
Notification Listeners | Is Feature Enabled uses the ACTIVATE notification listener for feature tests. Like impressions, the ACTIVATE notification listener isn't triggered if the user is in a rollout or if neither a test nor rollout is active. |
Source files
The table lists the language/platform source files containing the implementations.
Language/Platform | Source files |
---|---|
Android | OptimizelyClient.java |
C# | Optimizely.cs |
Java | Optimizely.java |
JavaScript | index.js |
Node | index.js |
Objective-C and Swift | Optimizely.h |
PHP | Optimizely.php |
Python | optimizely.py |
Ruby | optimizely.rb |