强制决策方法

云眼About 7 min

强制决策方法

本主题介绍强制决策方法,这些方法可用于强制用户进入云眼灰度发布(特性标帜)AB实验中的特定变体。

这些方法将通过强制用户进入特定变体来帮助测试和调试客户端应用程序的各种流。

云眼灰度发布(特性标帜)AB实验 Python SDK 将在做出任何决策之前检查强制决策。如果找到请求标帜的匹配项,Python SDK 会在做出正常决策之前立即返回强制决策(忽略受众条件流量分配):

下面介绍了 Python SDK 将遵循的具体场景:

标记到决策

  • SDK 将在给定标帜的任何决策调用开始时查找。如果为该标帜找到匹配的标帜到决策强制决策,它将返回该决定。

从实验规则到决策

  • SDK 将在决策开始时查找给定实验规则(标帜键)。如果为标帜找到匹配的实验规则到决策强制决策,它将返回决策。

从交付规则到决策

  • SDK 将在决策开始时查找给定的传递规则(标帜键)。如果找到匹配的传递规则到决策强制决策,它将返回该决策。

❗️

警告

在调用任何强制决策方法之前,必须将变体关联到标帜规则

对于强制决策,SDK 会像其他正常决策一样触发展示事件和通知(除非被 DISABLE_DECISION_EVENT 选项禁用)。

📘 注意

这些强制决策不是永久性的,将在重新初始化 EyeofcloudUserContext 时清除。

有关每种方法的更多信息,请单击下面的方法名称:

云眼分桶结果 EyeofcloudDecision上下文

Python

class EyeofcloudDecisionContext(object): def __init__(self, flag_key, rule_key):

云眼强制决策

Python

class EyeofcloudForcedDecision(object): def __init__(self, variation_key):

设置强制决策方法 - set_forced_decision()

版本

4.0.0

描述

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

参数

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

Parameter

Type

Description

context
required

Class

An instance of with the required and optional for the forced decision you want to set. EyeofcloudDecisionContext``flag_key``rule_key

decision
required

Class

An instance of with the required for the forced decision you want to set.EyeofcloudForcedDecision``variation_key

Returns

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

Example

See the full Python SDK example here.

Get Forced Decision Method - get_forced_decision()

Version

4.0.0

Description

Returns the forced decision () for a given . Returns the null if there is no matching item.variation_key``EyeofcloudDecisionContext

Parameters

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

Parameter

Type

Description

context
required

Class

An instance of with the required and optional for the forced decision you want to get. EyeofcloudDecisionContext``flag_key``rule_key

Returns

A forced decision instance for the context or nil if there is no matching item.EyeofcloudForcedDecision

Example

See the full Python SDK example here.

Remove Forced Decision Method - remove_forced_decision()

Version

4.0.0

Description

删除给定 的强制决策 ()。variation_key``EyeofcloudDecisionContext

参数

下表列出了 Python SDK 的必需参数和可选参数。

参数

类型

描述

所需的上下文

的实例,具有要删除的强制决策的必需和可选。EyeofcloudDecisionContext``flag_key``rule_key

返回

删除强制决策 () 时的成功/失败布尔状态。 variation_key

在此处查看完整的 Python SDK 示例。

删除所有强制决策方法 - remove_all_forced_decisions()

变体

4.0.0

描述

删除用户上下文的所有强制决策 ()。variation_key

参数

下表列出了 Python SDK 的必需参数和可选参数。

参数

类型

描述

没有

不适用

不适用

返回

成功/失败布尔状态。

在此处查看完整的 Python SDK 示例。

完整代码示例

Python

from eyeofcloud import eyeofcloud, eyeofcloud_user_context eyeofcloud = eyeofcloud.Eyeofcloud(sdk_key="sdk_key") user = eyeofcloud.create_user_context("test_user", attributes) flag_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1",None) flag_and_ab_test_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1","ab-test-1") flag_and_delivery_rule_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1","delivery-1") variation_a_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("variation-a") variation_b_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("variation-b") variation_on_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("on") # set a forced decision for a flag success = user.set_forced_decision(flag_context, variation_a_forced_decision) decision = user.decide("flag-1") # set a forced decision for an ab-test rule success = user.set_forced_decision(flag_and_ab_test_context, variation_b_forced_decision) decision = user.decide("flag-1") # set a forced variation for a delivery rule success = user.set_forced_decision(flag_and_delivery_rule_context, variation_on_forced_decision) decision = user.decide("flag-1") # get forced variations forced_decision = user.get_forced_decision(flag_context) print(f"[ForcedDecision] variation_key = {forced_decision}") # remove forced variations success = user.remove_forced_decision(flag_and_ab_test_context) success = user.remove_all_forced_decision()

参见

EyeofcloudUserContext

Source Files

Updated about 2 months ago


[

EyeofcloudUserContext

](/experimentation/v4.0.0-full-stack/docs/eyeofcloudusercontext-python)[

React SDK

](/experimentation/v4.0.0-full-stack/docs/javascript-react-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”