OptimizelyUserContext for the C# SDK
Describes the OptimizelyUserContext object for the Optimizely Feature Experimentation C# SDK, which allows you to make flag decisions and track events for a user context.
The OptimizelyUserContext object allows you to make flag decisions and track events for a user context that you have already created using the Create User Context method.
OptimizelyUserContext minimum SDK version
SDK v3.7 and higher.
Forced decision methods version
SetForcedDecision()
, GetForcedDecision()
, RemoveForcedDecision()
and RemoveAllForcedDecisions()
methods are supported on v3.11.0 and higher.
OptimizelyUserContext Updates
public class OptimizelyUserContext {
public OptimizelyUserContext(Optimizely optimizely,
string userId,
UserAttributes userAttributes,
ForcedDecisionsStore forcedDecisionsStore,
IErrorHandler errorHandler, ILogger logger)
// set an attribute for the user
public void SetAttribute(string key, object value)
// get attributes for the user
public UserAttributes GetAttributes()
// make a decision about which flag variation the user buckets into for the flag key
public OptimizelyDecision Decide(string key,
OptimizelyDecideOption[] options)
// make decisions about which flag variations the user buckets into for flag keys
public Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys,
OptimizelyDecideOption[] options)
// make decisions about which flag variations the user buckets into for all flags
public Dictionary<string, OptimizelyDecision> DecideAll(OptimizelyDecideOption[] options)
// track user event
public void TrackEvent(string eventName,
EventTags eventTags)
// sets a forced decision (variationKey) for a given decision context
public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForcedDecision decision)
// returns the forced decision (variationKey) for a given decision context
public OptimizelyForcedDecision GetForcedDecision(OptimizelyDecisionContext context)
// removes the forced decision (variationKey) for a given decision context
public bool RemoveForcedDecision(OptimizelyDecisionContext context)
// removes all the forced decisions (variationKeys) for the user context
public bool RemoveAllForcedDecisions()
}
Properties
Attribute | Type | Comment |
---|---|---|
userId | string | The ID of the user |
(optional) attributes | Dictionary | A dictionary of custom key-value pairs specifying attributes for the user that are used for audience targeting . You can pass the map with the user ID when you create the user. |
Methods
The table shows methods for the OptimizelyUserContext
object:
Method | Comment |
---|---|
SetAttribute | Pass a custom user attribute as a key-value pair to the user context. |
GetAttributes | Get attributes for the user |
Decide | Returns a decision result for a flag key for a user in an OptimizelyDecision object, containing all data required to deliver the flag rule. See Decide methods |
DecideForKeys | Returns a map of flag decisions for specified flag keys. See Decide methods |
DecideAll | Returns decisions for all active (unarchived) flags for a user. See Decide methods |
TrackEvent | Tracks a conversion event for a user (an action a user takes) and logs an error message if the specified event key does not match any existing events. See Track Event |
SetForcedDecision | Forces a user into a specific variation. See Set Forced Decision |
GetForcedDecision | Returns what variation the user was forced into. See Get Forced Decision |
RemoveForcedDecision | Removes a user from a specific forced variation. See Remove Forced Decision |
RemoveAllForcedDecisions | Removes a user from all forced variations. See Remove All Forced Decisions |
See also
Create User Context
Forced Decision methods
Source files
The language and platform source files containing the implementation for C# are available on GitHub.
Updated 19 days ago