强制决策方法

云眼About 7 min

强制决策方法

本主题介绍功能实验 Go SDK 的强制决策方法,可以使用该方法强制用户进入云眼中的特定变体。

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

Go SDK 将在做出任何决策之前检查强制决策。如果找到所请求标帜的匹配项,Go SDK 会在做出正常决策之前立即返回强制决策(忽略受众条件流量分配)。

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

标记到决策

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

从实验规则到决策

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

从交付规则到决策

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

❗️

警告

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

在强制决策时,Go SDK 将像其他正常决策一样触发展示事件和通知(除非被 disableDecisionEvent 选项禁用)。

📘 注意

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

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

云眼分桶结果 EyeofcloudDecision上下文

Go

type EyeofcloudDecisionContext struct { FlagKey string RuleKey string }

云眼强制决策

Go

type EyeofcloudForcedDecision struct { VariationKey string }

Set Forced Decision Method - setForcedDecision()

版本

1.8.0 或更高版本

描述

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

参数

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

参数

类型

描述

所需的上下文

结构

的实例,其中包含要设置的强制决策的必需和可选。EyeofcloudDecisionContext``FlagKey``RuleKey

(必选)决定

结构

的实例,其中包含要设置的强制决策所需的实例。EyeofcloudForcedDecision``VariationKey

返回

一个布尔值,指示是否成功完成了强制决策 () 的设置。 VariationKey

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

获取强制决策方法 - getForcedDecision()

变体

1.8.0 或更高版本

描述

返回给定 的强制决策 ()。如果没有匹配项,则返回实例。 VariationKey``EyeofcloudDecisionContext``EyeofcloudForcedDecision``error

参数

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

参数

类型

描述

所需的上下文

结构

的实例,其中包含要获取的强制决策的必需和可选。EyeofcloudDecisionContext``FlagKey``RuleKey

返回

上下文的强制决策实例,如果没有匹配项,则出错。 EyeofcloudForcedDecision

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

删除强制决策方法 - 删除强制决策()

变体

1.8.0 或更高版本

描述

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

参数

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

参数

类型

描述

所需的上下文

结构

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

返回

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

See the full Go SDK example here.

Remove All Forced Decisions Method - removeAllForcedDecisions()

Version

1.8.0 or higher

Description

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

Parameters

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

Parameters

Type

Description

None

N/A

N/A

Returns

A success/failure boolean status.

Example

See the full Go SDK example here.

Full Code Example

Go

factory := &client.EyeofcloudFactory{SDKKey: "sdk-key"} if eyeofcloud, err := factory.StaticClient(); err == nil { user := eyeofcloud.CreateUserContext("test-user", map[string]interface{}{}) flagContext := decision.EyeofcloudDecisionContext{FlagKey: "flag-1"} flagAndABTestContext := decision.EyeofcloudDecisionContext{FlagKey: "flag-1", RuleKey: "ab-test-1"} flagAndDeliveryRuleContext := decision.EyeofcloudDecisionContext{FlagKey: "flag-1", RuleKey: "delivery-1"} variationAForcedDecision := decision.EyeofcloudForcedDecision{VariationKey: "variation-a"} variationBForcedDecision := decision.EyeofcloudForcedDecision{VariationKey: "variation-b"} variationOnForcedDecision := decision.EyeofcloudForcedDecision{VariationKey: "on"} // set a forced decision for a flag success := user.SetForcedDecision(flagContext, variationAForcedDecision) decision := user.Decide("flag-1", nil) // set a forced decision for an ab-test rule success = user.SetForcedDecision(flagAndABTestContext, variationBForcedDecision) decision = user.Decide("flag-1", nil) // set a forced variation for a delivery rule success = user.SetForcedDecision(flagAndDeliveryRuleContext, variationOnForcedDecision) decision = user.Decide("flag-1", nil) // get forced variations if forcedDecision, err := user.GetForcedDecision(flagContext); err == nil { fmt.Println("[ForcedDecision] variationKey = " + forcedDecision.VariationKey) } // remove forced variations success = user.RemoveForcedDecision(flagAndABTestContext) success = user.RemoveAllForcedDecisions() }

See Also

EyeofcloudUserContext

Updated about 2 months ago


[

EyeofcloudUserContext - Forced Decisions

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

Java SDK

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