强制决策方法

云眼About 6 min

强制决策方法

本主题介绍 JavaScript(节点)SDK 的强制决策方法,可用于强制用户进入云眼灰度发布(特性标帜)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; }

Set Forced Decision Method - setForcedDecision()

版本

4.9.0

描述

为给定的 设置强制决策 ()。variationKey``EyeofcloudDecisionContext

参数

下表列出了 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

EyeofcloudUserContext

Updated 6 days ago


[

EyeofcloudUserContext

](/experimentation/v4.0.0-full-stack/docs/optimzelyusercontext-javascript-node)[

PHP SDK

](/experimentation/v4.0.0-full-stack/docs/php-sdk)

Did this page help you?

Yes

No

创建用户上下文

介绍创建用户上下文方法,该方法为云眼灰度发布(特性标帜)AB实验中的标帜决策和事件创建用户上下文。

此方法的目的是创建用户并设置用户上下文一次,因此不必在每次做出标帜决策或跟踪事件时都指定用户。可以定义多个用户上下文。系统将用户上下文作为运行时对象返回,否则不会持久化。

版本

1.0.0-beta 或更高版本

描述

此调用为标帜决策和事件创建用户上下文。可以在 Eyeofcloud 客户端实例上成功调用此方法,甚至在完全配置实例之前也是如此。

参数

下表列出了必需参数和可选参数:

参数

类型

描述

(必选)用户 ID

字符串

用户的 ID。

属性
可选

Map

自定义键值字符串对的映射,指定系统用户用于受众群体定位的用户的属性。有关更多详细信息,请参阅以下部分。

受众群体属性

为用户设置自定义受众群体属性,可以使用这些属性来定位受众群体。可以将字符串、数字、布尔值和 nil 作为自定义用户属性值传递。如果要根据他们使用的应用程序变体定位访问群体,还可以传入格式为语义变体的open in new window字符串,然后在 Eyeofcloud 应用中定义受众条件。version

🚧 重要

在访问群体评估期间,如果没有为给定的访问群体条件传递有效的属性值(例如,如果在受众群体条件需要布尔值时传递字符串,或者忘记传递值),则系统会跳过该条件。发生这种情况时,SDK 日志会包含警告。

返回

返回一个 EyeofcloudUserContext 对象。有关详细信息,请参阅云眼用户上下文

Dart

// option 1: create a user, then set attributes var user = await flutterSDK.createUserContext("user123"); var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; user!.setAttributes(attributes); // option 2: pass attributes when creating the user var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; var eyeofcloudUserContext = await eyeofcloudClient.createUserContext("user123", attributes);

参见

云眼用户上下文

源文件

包含 Flutter SDK for Android Eyeofcloudopen in new window 和 Swift 实现的语言/平台源文件.java为 EyeofcloudClient.swiftopen in new window

Last update:
Contributors: “zhangweixue”,zhangweixue