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

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

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

Also, if you haveReal-Time Audiences for Feature Experimentation configured between Optimizely Data Platform (ODP) and Optimizely Feature Experimentation, you can evaluate if your user would qualify for a real-time audience segment.

OptimizelyUserContext minimum SDK version

OptimizelyUserContext is supported on SDK v3.8 and higher.

Forced decision methods minimum SDK version

set_forced_decision(),get_forced_decision(),remove_forced_decision() andremove_all_forced_decisions() methods are supported on v3.10.0 and higher.

Real-Time Audiences for Feature Experimentation minimum SDK version

fetch_qualified_segments() andqualified_for?() methods are supported on v5.0.0 and higher.

OptimizelyUserContext definition

The following code shows the object definition forOptimizelyUserContext:

module Optimizely  class OptimizelyUserContext    attr_reader :user_id        # Create an instance of the Optimizely User Context. Pass in user id and optionally user attributes     def initialize(optimizely_client, user_id, user_attributes)    # set an attribute for the user    def set_attribute(attribute_key, attribute_value)        # get attributes for the user    def user_attributes    # make a decision about which flag variation the user buckets into for the flag key     def decide(key, options = nil)    # make decisions about which flag variations the user buckets into for flag keys     def decide_for_keys(keys, options = nil)    # make decisions about which flag variations the user buckets into for all flags     def decide_all(options = nil)    # track user event    def track_event(event_key, event_tags = nil)          # OptimizelyDecisionContext    OptimizelyDecisionContext = Struct.new(:flag_key, :rule_key)          # OptimizelyForcedDecision    OptimizelyForcedDecision = Struct.new(:variation_key)    # Sets the forced decision (variation_key) for a given decision context    def set_forced_decision(context, decision)    # Returns the forced decision for a given decision context    def get_forced_decision(context)    # Removes the forced decision for a given decision context    def remove_forced_decision(context)    # Removes all forced decisions bound to this user context    def remove_all_forced_decisions          # The following methods require Real-Time Audiences for Feature Experimentation     # See note following the code sample.    # An array of audience segment names that the user is qualified for.     # The result of **fetch_qualified_segments()** is saved here.     # Can be nil if not properly updated with fetch_qualified_segments().     #     # You 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.       def qualified_segments           # Fetch all qualified segments for the user context.    # If no callback is provided, this method fetches the qualified segments    # and return a boolean signifying success.    #    # If a callback is provided, the method fetches segments in a separate thread,     # invoke the provided callback when results are available, and return the thread handle.     def fetch_qualified_segments(options, &block)      # Check is the user qualified for the given segment.     def qualified_for?(segment)  endend
📘

Note

You must first configureReal-Time Audiences for Feature Experimentation to run thequalified_segments(),fetch_qualified_segments(), andqualified_for?() methods.

Properties

The following table shows attributes for theOptimizelyUserContext object:

Attribute

Type

Comment

user_id

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

set_attribute

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 in an OptimizelyDecision object, which contains all data required to deliver the flag rule.SeeDecide methods

decide_for_keys

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

decide_all

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

track_event

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.SeeTrack Event

set_forced_decision

Forces a user into a specific variation.SeeSet Forced Decision

get_forced_decision

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

remove_forced_decision

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

remove_all_forced_decisions

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

fetch_qualified_segments **

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

qualified_for? **

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

** RequiresReal-Time Audiences for Feature Experimentation.

See Also

Create User Context

Source files

The language and platform source files containing the implementation for Ruby are available onGithub.com.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp