OptimizelyDecision for the JavaScript SDK v6
Describes the OptimizelyDecision object for the JavaScript(Browser) SDK, which is returned from the decide methods in Optimizely Feature Experimentation.
Warning
This content covers the Feature Experimentation JavaScript (Browser) SDK v6 features currently in pre-production testing and is subject to change before release
For the latest released version, see JavaScript (Browser) SDK.
Minimum SDK version
v6.0.0+
Object model
The following code shows the interface of the OptimizelyDecision object:
interface OptimizelyDecision {
variationKey: string | null;
enabled: boolean;
variables: { [variableKey: string]: unknown };
ruleKey: string | null;
flagKey: string;
userContext: OptimizelyUserContext;
reasons: string[];
}
The following table describes the fields of the OptimizelyDecision object:
Field | Type | Description |
---|---|---|
enabled | Boolean | Whether the flag is enabled or not. Optimizely Feature Experimentation never returns null for this field; it returns false when it fails to make a decision due to an error. |
variables | map | Key-value pairs of all the flag variables. When there are no variables defined for the flag or SDK cannot get variables, this field returns an empty map. When SDK fails to get variables for a decision, the Reasons field includes the error messages regardless of the Include Reasons option. |
variationKey | String (nullable) | When SDK fails to make a decision, this field returns null and the Reasons field includes the log messages if the Include Reasons option is set. |
ruleKey | String (nullable) | The key of the flag rule that the user bucketed into for this decision. When a valid rule key is not available, returns a copy of the experiment key. Returns null if neither a valid rule key nor experiment key is found. |
flagKey | String | The key of the flag for which the decision was made. |
userContext | OptimizelyUserContext | The user associated with the call to the Decide method. |
reasons | Array | An array of relevant error and log messages, in chronological order. Optimizely Feature Experimentation returns messages in this field in the following situations:
|
Reasons
The returned decision object includes error and log messages in the Reasons field.
Error reasons
For the sake of consistency with other decision results, Optimizely Feature Experimentation returns a decision with null fields instead of throwing errors or exceptions.
Critical errors are always included in the reasons field of the returned decision object regardless of the include reasons option you set on the Decide method.
Error | Possible reasons |
---|---|
null variationKey |
|
empty variables |
|
Log reasons
Optimizely Feature Experimentation collects log messages in the Reasons field of the returned OptimizelyDecision object in the order in which they are logged.
The following types of log messages are only included in the Reasons field if you set the Include Reasons option on the Decide method:
- Log messages related to bucketing users based on audiences or attributes.
- Log messages related to bucketing users based on traffic percentages.
Examples
The language and platform source files containing the implementation for JavaScript are available on GitHub.
Updated about 22 hours ago