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 Go SDK

Describes the OptimizelyUserContext object for the Optimizely Feature Experimentation Go SDK, which lets you make flag decisions and track events for a user context.

The OptimizelyUserContext object lets you make flag decisions and track events for a user context that you created using theCreate User Context method.

Additionally, if you haveReal-Time Audiences for Feature Experimentation configured, you can evaluate if your user would qualify for a real-time audience.

OptimizelyUserContext minimum SDK version

OptimizelyUserContext is supported on SDK v1.7.0 and higher.

Forced decision methods minimum SDK version

SetForcedDecision(),GetForcedDecision(),RemoveForcedDecision() andRemoveAllForcedDecisions() methods are supported on v1.8.0 and higher.

Real-Time Audiences for Feature Experimentation minimum SDK version

FetchQualifiedSegments() andIsQualifiedFor() methods are supported on version 2.0.0 and higher.

OptimizelyUserContext definition

The following code shows the object definition forOptimizelyUserContext:

type OptimizelyUserContext struct {  UserID     string                  Attributes map[string]interface{}} // GetOptimizely returns optimizely client instance for Optimizely user contextfunc (o OptimizelyUserContext) GetOptimizely() *OptimizelyClient // GetUserID returns userID for Optimizely user contextfunc (o OptimizelyUserContext) GetUserID() string // GetUserAttributes returns user attributes for Optimizely user contextfunc (o OptimizelyUserContext) GetUserAttributes() map[string]interface{} // SetAttribute sets an attribute for a given key.func (o *OptimizelyUserContext) SetAttribute(key string, value interface{}) // Decide returns a decision result for a given flag key and a user context, which contains// all data required to deliver the flag or experiment.func (o *OptimizelyUserContext) Decide(key string, options []decide.OptimizelyDecideOptions) OptimizelyDecision // DecideAll returns a key-map of decision results for all active flag keys with options.func (o *OptimizelyUserContext) DecideAll(options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision // DecideForKeys returns a key-map of decision results for multiple flag keys and options.func (o *OptimizelyUserContext) DecideForKeys(keys []string, options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision // TrackEvent generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely// log endpoint for results processing.func (o *OptimizelyUserContext) TrackEvent(eventKey string, eventTags map[string]interface{}) (err error) // OptimizelyDecisionContexttype OptimizelyDecisionContext struct {  FlagKey string  RuleKey string} // OptimizelyForcedDecisiontype OptimizelyForcedDecision struct {  VariationKey string} // SetForcedDecision sets the forced decision (variation key) for a given decision context (flag key and optional rule key).// returns true if the forced decision has been set successfully.func (o *OptimizelyUserContext) SetForcedDecision(context pkgDecision.OptimizelyDecisionContext, decision pkgDecision.OptimizelyForcedDecision) bool // GetForcedDecision returns the forced decision for a given flag and an optional rulefunc (o *OptimizelyUserContext) GetForcedDecision(context pkgDecision.OptimizelyDecisionContext) (pkgDecision.OptimizelyForcedDecision, error) // RemoveForcedDecision removes the forced decision for a given flag and an optional rule.func (o *OptimizelyUserContext) RemoveForcedDecision(context pkgDecision.OptimizelyDecisionContext) bool // RemoveAllForcedDecisions removes all forced decisions bound to this user context.func (o *OptimizelyUserContext) RemoveAllForcedDecisions() bool //// The following methods require Real-Time Audiences for Feature Experimentation. // See note following this code sample. // // GetQualifiedSegments returns an array of segment names that the user is qualified for. // The result of **FetchQualifiedSegments()** is saved here. // Can be nil if not properly updated with FetchQualifiedSegments(). func (o *OptimizelyUserContext) GetQualifiedSegments() []string // SetQualifiedSegments can read and write directly to the qualified segments array. // This lets you bypass the remote fetching process from ODP // or for utilizing your own fetching service.   func (o *OptimizelyUserContext) SetQualifiedSegments(qualifiedSegments []string)      // FetchQualifiedSegments fetches all qualified segments for the user context.// The segments fetched are saved in the **qualifiedSegments** array// and can be accessed any time. func (o *OptimizelyUserContext) FetchQualifiedSegments(options []pkgOdpSegment.OptimizelySegmentOption) (success bool) // FetchQualifiedSegmentsAsync fetches all qualified segments aysnchronously for the user context. // This method fetches segments in a separate go routine and invoke the provided // callback when results are available.func (o *OptimizelyUserContext) FetchQualifiedSegmentsAsync(options []pkgOdpSegment.OptimizelySegmentOption, callback func(success bool)) // IsQualifiedFor returns true if the user is qualified for the given segment namefunc (o *OptimizelyUserContext) IsQualifiedFor(segment string) bool
📘

Note

You must first configureReal-Time Audiences for Feature Experimentation to access theGetQualifiedSegments(),SetQualifiedSegments(),FetchQualifiedSegments(),FetchQualifiedSegmentsAsync(), andIsQualifiedFor() methods.

Properties

The following table shows attributes for theOptimizelyUserContext object:

Attribute

Type

Comment

UserID

String

The ID of the user

Attributes(optional)

Map

A 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.

GetUserAttributes

Get attributes for the user

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

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 ODP real-time audiences for which the user context qualified. SeeReal-Time Audiences for Feature Experimentation segment qualification methods for the Go SDK.

FetchQualifiedSegmentsAsync **

Fetch all ODP real-time audiences that the user context qualified for asynchronously. SeeReal-Time Audiences for Feature Experimentation segment qualification methods for the Go SDK.

IsQualifiedFor **

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

** RequiresReal-Time Audiences for Feature Experimentation.

See also

Create User Context

Source files

The language and platform source files containing the implementation for Go is available onGitHub.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp