Movatterモバイル変換


[0]ホーム

URL:


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

Forced Decision methods for the Flutter SDK

Describes the Forced Decision methods, which you can use with the Flutter SDK to force users into a specific variation in Optimizely Feature Experimentation.

Use these methods to test and debug various flows of your client applications by forcing users into a specific variation.

The Flutter SDK checks if any Forced Decision methods were implemented before making any decisions. If it finds a matching for the requested flag, the Flutter SDK returns the forced decision immediately (audience conditions and ignorestraffic allocations) before making normal decisions.

The following describes specific scenarios the Flutter SDK follows:

Flag-to-Decision

  • SDK looks up at the beginning of anydecide call for the given flag. If a matching Flag-to-Decision forced decision is found for the flag, it returns the decision.

Experiment-Rule-to-Decision

  • SDK looks up at the beginning of the decision for the given experiment rule (of the flag key). If a matching Experiment-Rule-to-Decision forced decision is found for the flag, it returns the decision.

Delivery-Rule-to-Decision

  • SDK looks up at the beginning of the decision for the given delivery rule (of the flag key). If a matching Delivery-Rule-to-Decision forced decision is found, it returns the decision.
❗️

Warning

You must associate your variations to aflag rule before calling any Forced Decision methods.

On forced decisions, SDK fires impression events and notifications just like other normal decisions (unless disabled by thedisableDecisionEvent option).

📘

Note

These forced decisions are not persistent and the system clears them when theOptimizelyUserContext is reinitialized.

For information about each Forced Decision method, click on the method name below:

OptimizelyDecisionContext

class OptimizelyDecisionContext {  String flagKey;  String? ruleKey;  OptimizelyDecisionContext(this.flagKey, [this.ruleKey]);}

OptimizelyForcedDecision

class OptimizelyForcedDecision {  String variationKey;  OptimizelyForcedDecision(this.variationKey);}

Set Forced Decision method –setForcedDecision()

Version

1.0.1 or higher

Description

Sets a forced decision (variationKey) for a givenOptimizelyDecisionContext.

Parameters

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

Parameter

Type

Description

contextrequired

Struct

An instance ofOptimizelyDecisionContext with the requiredflagKey and optionalruleKey for the forced decision you want to set.

decision
required

Struct

An instance ofOptimizelyForcedDecision with the requiredvariationKey for the forced decision you want to set.

Returns

A boolean value that indicates if setting the forced decision (variationKey) was completed successfully.

Example

See theFull code example section.

Get Forced Decision method –getForcedDecision()

Version

1.0.1 or higher

Description

Returns the forced decision (variationKey) for a givenOptimizelyDecisionContext. Returns theOptimizelyForcedDecision instance or null if there is no matching item.

Parameters

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

Parameter

Type

Description

contextrequired

struct

An instance ofOptimizelyDecisionContext with the requiredflagKey and optionalruleKey for the forced decision you want to get.

Returns

A forced decisionOptimizelyForcedDecision instance for the context or null if there is no matching item.

Example

See theFull code example section.

Remove Forced Decision method –removeForcedDecision()

Version

1.0.1 or higher

Description

Removes the forced decision (variationKey) for a givenOptimizelyDecisionContext.

Parameters

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

Parameters

Type

Description

contextrequired

struct

An instance ofOptimizelyDecisionContext with the requiredflagKey and optionalruleKey for the forced decision you want to remove.

Returns

A success or failure boolean status if the forced decision (variationKey) was removed.

Example

See theFull code example section.

Remove All Forced Decisions method –removeAllForcedDecisions()

Version

1.0.1 or higher

Description

Removes all forced decisions (variationKey) for the user context.

Parameters

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

ParametersTypeDescription
NoneN/AN/A

Returns

A success or failure boolean status.

Example

See theFull code example section.

Full code example

/* Create the OptimizelyUserContext, passing in the UserId and Attributes */var user = await optimizelyClient.createUserContext(userId: "user-id");var flagContext = OptimizelyDecisionContext("flag-1");var flagAndABTestContext = OptimizelyDecisionContext("flag-1", "exp-1");var flagAndDeliveryRuleContext = OptimizelyDecisionContext("flag-1", "delivery-1");var variationAForcedDecision = OptimizelyForcedDecision("variation-a");var variationBForcedDecision = OptimizelyForcedDecision("variation-b");var variationOnForcedDecision = OptimizelyForcedDecision("on");// set a forced decision for a flagvar success = await user!.setForcedDecision(flagContext, variationAForcedDecision);var decision = await user.decide("flag-1");// set a forced decision for an ab-test rulesuccess = await user.setForcedDecision(flagAndABTestContext, variationBForcedDecision);decision = await user.decide("flag-1");// set a forced variation for a delivery rulesuccess = await user.setForcedDecision(flagAndDeliveryRuleContext, variationOnForcedDecision);decision = await user.decide("flag-1");// get forced variationsvar forcedDecision = await user.getForcedDecision(flagContext);print("[ForcedDecision] variationKey = ${forcedDecision.variationKey}");// remove forced variationssuccess = await user.removeForcedDecision(flagAndABTestContext);success = await user.removeAllForcedDecisions();

See Also

OptimizelyUserContext

Source files

The language and platform source files containing the implementation for Flutter are available on GitHub.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp