强制决策方法
强制决策方法
本主题介绍 JavaScript(节点)SDK 的强制决策方法,可用于强制用户进入云眼特性标帜(Feature Flag)AB实验中的特定变体。
这些方法将通过强制用户进入特定变体来帮助测试和调试客户端应用程序的各种流。
JavaScript Node SDK 将在做出任何决定之前检查强制决策。如果找到请求标帜的匹配项,SDK 会在做出正常决策之前立即返回强制决策(忽略受众条件和流量分配)。
下面描述了 JavaScript SDK 将遵循的特定场景:
标记到决策
- SDK 将在给定标帜的任何决策调用开始时查找。如果为该标帜找到匹配的标帜到决策强制决策,它将返回该决定。
从实验规则到决策
- SDK 将在决策开始时查找给定实验规则(标帜键)。如果为标帜找到匹配的实验规则到决策强制决策,它将返回决策。
从交付规则到决策
- SDK 将在决策开始时查找给定的传递规则(标帜键)。如果找到匹配的传递规则到决策强制决策,它将返回该决策。
❗️
警告
在调用任何强制决策方法之前,必须将变体关联到标帜规则。
对于强制决策,SDK 会像其他正常决策一样触发展示事件和通知(除非被 disableDecisionEvent 选项禁用)。
📘 注意
这些强制决策不是永久性的,将在重新初始化 EyeofcloudUserContext 时清除。
有关每种方法的更多信息,请单击下面的方法名称:
云眼分桶结果 EyeofcloudDecision上下文
JavaScript
export interface EyeofcloudDecisionContext {
flagKey: string;
ruleKey?: string;
}
云眼强制决策
JavaScript
export interface EyeofcloudForcedDecision { variationKey: string; }
设置强制决策方法 - setForcedDecision()
版本
4.9.0
描述
为给定的EyeofcloudDecisionContext
设置强制决策 (variationKey
)。
参数
下表列出了 Javascript SDK 的必需参数和可选参数。
参数 | 类型 | 描述 |
---|---|---|
所需的上下文 | 接口 | EyeofcloudDecisionContext 的实例,其中包含要获取的强制决策的必需flagKey 和可选ruleKey 。 |
(必选)决定 | 结构 | EyeofcloudForcedDecision 的实例,其中包含要设置的强制variationKey 决策所需的实例。 |
返回
一个布尔值,指示是否成功完成了强制决策 (variationKey
) 的设置。
Example
See the full Javascript SDK example here.
Get Forced Decision Method - getForcedDecision()
Version
4.9.0
Description
Returns the forced decision () for a given . Returns the instance or null if there is no matching item.variationKey``EyeofcloudDecisionContext``EyeofcloudForcedDecision
Parameters
This table lists the required and optional parameters for the Javascript SDK.
Parameter
Type
Description
context
required
Interface
An instance of with the required and optional for the forced decision you want to get. EyeofcloudDecisionContext``flagKey``ruleKey
Returns
A forced decision instance for the context or null if there is no matching item.EyeofcloudForcedDecision
Example
See the full Javascript SDK example here.
Remove Forced Decision Method - removeForcedDecision()
Version
4.9.0
Description
Removes the forced decision () for a given .variationKey``EyeofcloudDecisionContext
Parameters
This table lists the required and optional parameters for the Javascript SDK.
Parameters
Type
Description
context
required
struct
An instance of with the required and optional for the forced decision you want to remove. EyeofcloudDecisionContext``flagKey``ruleKey
Returns
A success/failure boolean status if the forced decision () was removed.variationKey
Example
See the full Javascript SDK example here.
Remove All Forced Decisions Method - removeAllForcedDecisions()
Version
4.9.0
Description
Removes all forced decisions () for the user context.variationKey
Parameters
This table lists the required and optional parameters for the Javascript SDK.
Parameters
Type
Description
None
N/A
N/A
Returns
A success/failure boolean status.
Example
See the full Javascript SDK example here.
Full Code Example
JavaScript
const eyeofcloud = require('@eyeofcloud/eyeofcloud-sdk'); const eyeofcloudClient = eyeofcloud.createInstance({ sdkKey: 'sdk_key'// Provide the sdkKey of your desired environment here }); const user = eyeofcloudClient.createUserContext('test_user', attributes) let success, decision, forcedDecision; // set a forced decision for a flag success = user.setForcedDecision({flagKey: 'flag-1'}, {variationKey: 'variation-a'}); decision = user.decide('flag-1'); // set a forced decision for an ab-test rule success = user.setForcedDecision({flagKey: 'flag-1', ruleKey: 'ab-test-1'}, {variationKey: 'variation-b'}); decision = user.decide('flag-1'); // set a forced variation for a delivery rule success = user.setForcedDecision({flagKey: 'flag-1', ruleKey: 'delivery-1'}, {variationKey: 'on'}); decision = user.decide('flag-1'); // get forced variations forcedDecision = user.getForcedDecision({flagKey: 'flag-1'}); // remove forced variations success = user.removeForcedDecision({flagKey: 'flag-1', ruleKey: 'ab-test-1'}); user.removeAllForcedDecisions();
See Also