Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Get Forced Variation

This topic describes the Get Forced Variation method, which returns the forced variation set by Set Forced Variation, or null if no variation was forced.

Returns the forced variation set by Set Forced Variation, or null if no variation was forced.

A user can be forced into a variation for a given experiment for the lifetime of the Optimizely client. This method gets the variation that the user has been forced into. The forced variation value is runtime only and does not persist across application launches.

Version

SDK v3.0, v3.1

Description

Forced bucketing variations take precedence over whitelisted variations, variations saved in a User Profile Service (if one exists), and the normal bucketed variation. Variations are overwritten when Set Forced Variation is invoked.

📘

Note

A forced variation only persists for the lifetime of an Optimizely client.

Parameters

This table lists the required and optional parameters for the Ruby SDK.

ParameterTypeDescription
experiment_key
required
stringThe key of the experiment to retrieve the forced variation.
user_id
required
stringThe ID of the user in the forced variation.

Returns

@return [String] The variation the user was bucketed into, or nil if setForcedVariation failed to force the user into the variation.

Example

variation_key = optimizely_client.get_forced_variation('my_experiment_key', 'user_123');

Source files

The language/platform source files containing the implementation for Ruby is optimizely.rb.