Movatterモバイル変換


[0]ホーム

URL:


Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog InFeature Experimentation
Dev guide
All
Pages
Start typing to search…

OptimizelyUserContext for the Android SDK

Describes theOptimizelyUserContext object, which lets you to make flag decisions and track events for a user context.

TheOptimizelyUserContext object lets you to make flag decisions and track events for a user context that you have already created using theCreate User Context method.

OptimizelyUserContext minimum SDK version

OptimizelyUserContext is supported on the Optimizely Feature Experimentation Android SDK v3.7 and higher.

Forced decision methods minimum SDK version

setForcedDecision(),getForcedDecision(),removeForcedDecision() andremoveAllForcedDecisions() methods are supported on v3.13 and higher.

Real-Time Audiences for Feature Experimentation minimum SDK version

fetchQualifiedSegments() andisQualifiedFor() methods are supported on v4.0.0 and higher.

OptimizelyUserContext definition

The following code shows the object definition forOptimizelyUserContext:

class OptimizelyUserContext(optimizely: Optimizely,                            userId: String,                            attributes: Map<String, Any?>?) {    val userId: String    val attributes: MutableMap<String?, Any?>    // set an attribute for the user    fun setAttribute(key: String, value: Any?)    // make a decision about which flag variation the user buckets into for the flag key    fun decide(key: String,               options: List<OptimizelyDecideOption?>? = emptyList()): OptimizelyDecision    // make decisions about which flag variations the user buckets into for flag keys    fun decideForKeys(keys: List<String?>?,                      options: List<OptimizelyDecideOption?>? = emptyList()): Map<String, OptimizelyDecision>    // make decisions about which flag variations the user buckets into for all flags    fun decideAll(options: List<OptimizelyDecideOption?>? = emptyList()): Map<String, OptimizelyDecision>    // track user event    fun trackEvent(eventName: String,                   eventTags: Map<String?, *>? = emptyMap<String?, Any>())    // sets a forced decision (variationKey) for a given decision context    fun setForcedDecision(optimizelyDecisionContext: OptimizelyDecisionContext,                          optimizelyForcedDecision: OptimizelyForcedDecision): Boolean    // returns the forced decision (variationKey) for a given decision context    fun getForcedDecision(optimizelyDecisionContext: OptimizelyDecisionContext): OptimizelyForcedDecision?    // removes the forced decision (variationKey) for a given decision context    fun removeForcedDecision(optimizelyDecisionContext: OptimizelyDecisionContext): Boolean    // removes all the forced decisions (variationKeys) for the user context    fun removeAllForcedDecisions(): Boolean      //    // The following methods require Real-Time Audiences for Feature Experimentation enabled.     // See note below code sample.     //    // An array of audience names that the user is qualified for.     // The result of **fetchQualifiedSegments()** is saved here.     // Can be nil if not properly updated with fetchQualifiedSegments().     //     //  You can read and write directly to the qualified segments array.     //  This let you bypass the remote fetching process from     //  Optimizely Data Platform or for utilizing your own fetching service.       val qualifiedSegments: MutableMap<String?, Any?>    // Fetch all qualified segments for the user context.     ///    /// The segments fetched are saved in **qualifiedSegments** and can be accessed any time.    /// On failure, **qualifiedSegments** is nil and one of the following errors are returned:    /// - OptimizelyError.invalidSegmentIdentifier    /// - OptimizelyError.fetchSegmentsFailed(String)    ///    /// - Parameters:    ///   - options: A set of options for fetching qualified segments (optional).    ///   - completionHandler: A completion handler to be called with the fetch result.     ///       - On success, it passes a non-nil segments array (can be empty) with a nil error.     ///       - On failure, it passes a non-nil error with a nil segments array.    fun fetchQualifiedSegments(options: [OptimizelySegmentOption] = [],                                     completionHandler: ([String], OptimizelyError?) -> Void)    //  Check is the user qualified for the given segment.     /// - Parameter segment: the segment name to check qualification for.    /// - Returns: true if qualified.    fun isQualifiedFor(segment: String) -> Bool}
public class OptimizelyUserContext {    public String getUserId()    public Map<String, Object> getAttributes()    public OptimizelyUserContext(Optimizely optimizely,                                  String userId,                                  Map<String, Object> attributes)          // set an attribute for the user    public void setAttribute(String key, Object value)        // make a decision about which flag variation the user buckets into for the flag key    public OptimizelyDecision decide(String key,                                      List<OptimizelyDecideOption> options)        // make decisions about which flag variations the user buckets into for flag keys      public Map<String, OptimizelyDecision> decideForKeys(List<String> keys,                                       List<OptimizelyDecideOption> options)        // make decisions about which flag variations the user buckets into for all flags      public Map<String, OptimizelyDecision> decideAll(List<OptimizelyDecideOption> options)        // track user event      public void trackEvent(String eventName, Map<String, ?> eventTags)      // sets a forced decision (variationKey) for a given decision context    public Boolean 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 Boolean removeForcedDecision(OptimizelyDecisionContext context)    // removes all the forced decisions (variationKeys) for the user context    public Boolean removeAllForcedDecisions()          //    // The following methods require the Audience targeting with Optimizely Data Platform     // integration enabled. See note below code sample.     //    // An array of segment names that the user is qualified for.     // The result of **fetchQualifiedSegments()** will be saved here.     // Can be nil if not properly updated with fetchQualifiedSegments().     //     //  You can read and write directly to the qualified segments array.     //  This allows for bypassing the remote fetching process from ODP     //  or for utilizing your own fetching service.       public var qualifiedSegments: [String]?     // Fetch all qualified segments for the user context.     ///    /// The segments fetched will be saved in **qualifiedSegments** and can be accessed any time.    /// On failure, **qualifiedSegments** will be nil and one of these errors will be returned:    /// - OptimizelyError.invalidSegmentIdentifier    /// - OptimizelyError.fetchSegmentsFailed(String)    ///    /// - Parameters:    ///   - options: A set of options for fetching qualified segments (optional).    ///   - completionHandler: A completion handler to be called with the fetch result. On success, it'll pass a non-nil segments array (can be empty) with a nil error. On failure, it'll pass a non-nil error with a nil segments array.    public func fetchQualifiedSegments(options: [OptimizelySegmentOption] = [],                                     completionHandler: @escaping ([String]?, OptimizelyError?) -> Void)    //  Check is the user qualified for the given segment.     /// - Parameter segment: the segment name to check qualification for.    /// - Returns: true if qualified.    public func isQualifiedFor(segment: String) -> Bool    }
📘

Note

You must first enable theReal-Time Audiences for Feature Experimentation integration to use thequalifiedSegments(),fetchQualifiedSegments(), andisQualifiedFor() methods. SeeReal-Time Audiences for Feature Experimentation for information.

Properties

The following table shows attributes for theOptimizelyUserContext object:

AttributeTypeComment
userIdStringThe ID of the user
(optional) attributesMapA map of custom key-value pairs specifying attributes for the user that are used foraudience targeting. You can pass the map with the user ID when you create the user.

Methods

The following table shows methods for theOptimizelyUserContext object:

Method

Comment

setAttribute

Pass a custom user attribute as a key-value pair to the user context.

decide

Returns a decision result for a flag key for a user. The decision result is returned in an OptimizelyDecision object, and contains all data required to deliver the flag rule.SeeDecide methods

decideAll

Returns decisions for all active (unarchived) flags for a user.SeeDecide methods

decideForKeys

Returns a map of flag decisions for specified flag keys.SeeDecide methods

trackEvent

Tracks a conversion event (in other words, an action a user takes) for a user. Logs an error message if the specified event key doesn't match any existing events.SeeTrack Event

setForcedDecision

Forces a user into a specific variation.SeeSet Forced Decision

getForcedDecision

Returns what variation the user was forced into.SeeGet Forced Decision

removeForcedDecision

Removes a user from a specific forced variation.SeeRemove Forced Decision

removeAllForcedDecisions

Removes a user from all forced variations.SeeRemove All Forced Decisions

fetchQualifiedSegments **

Fetch all Optimizely Data Platform (ODP) real-time audiences that the user context qualified for. SeeReal-Time Audiences for Feature Experimentation segment qualification methods for the Android SDK.

isQualifiedFor **

Check if the user context qualified for a given ODP real-time audience. SeeReal-Time Audiences for Feature Experimentation segment qualification methods for the Android SDK.

** RequiresReal-Time Audiences for Feature Experimentation.

Source files

The language and platform source files containing the implementation for the Android SDK are available onGitHub.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp