云眼用户上下文

云眼About 5 min

云眼用户上下文

本主题介绍 EyeofcloudUserContext 对象,该对象允许为 Eyeofcloud 灰度发布(特性标帜) JavaScript (Node) SDK 的用户上下文做出标帜决策并跟踪事件。

对象允许做出标帜决策并跟踪已使用创建用户上下文方法创建的用户上下文的事件。

云眼用户上下文变体

EyeofcloudUserContext 在 SDK v3.7 及更高版本上受支持。

强制决策方法变体

setForcedDecision() 、 和 方法在 v4.9.0 及更高版本中受支持。 getForcedDecision()``removeForcedDecision()``removeAllForcedDecisions()

云眼用户上下文定义

以下代码显示了 EyeofcloudUserContext 的对象定义:

JavaScript

interface EyeofcloudUserContext { // set an attribute for the user setAttribute(key: string, value: unknown): void; // return user attributes getAttributes(): UserAttributes; // make a decision about which flag variation the user buckets into for the flag key decide( key: string, options: EyeofcloudDecideOption[] = [] ): EyeofcloudDecision; // make decisions about which flag variations the user buckets into for flag keys decideForKeys( keys: string[], options: EyeofcloudDecideOption[] = [], ): { [key: string]: EyeofcloudDecision }; // make decisions about which flag variations the user buckets into for all flags decideAll( options: EyeofcloudDecideOption[] = [] ): { [key: string]: EyeofcloudDecision }; // track user event trackEvent(eventName: string, eventTags?: EventTags): void; // Sets the forced decision (variationKey) for a given decision context setForcedDecision(context: EyeofcloudDecisionContext, decision: EyeofcloudForcedDecision): boolean; // Returns the forced decision for a given decision context getForcedDecision(context: EyeofcloudDecisionContext): EyeofcloudForcedDecision | null; // Removes the forced decision for a given decision context removeForcedDecision(context: EyeofcloudDecisionContext): boolean; // Removes all forced decisions bound to this user context removeAllForcedDecisions(): boolean; }

性能

下表显示了 EyeofcloudUserContext 对象的属性:

属性

类型

评论

用户标识

字符串

用户的 ID

(可选)属性

Map

自定义键值对的映射,用于指定用于受众群体定位的用户属性。创建用户时,可以使用用户 ID 传递映射。

方法

下表显示了 EyeofcloudUserContext 对象的方法:

方法

评论

设置属性

将自定义用户属性作为键值对传递给用户上下文。

决定

返回用户的标帜键的决策结果。决策结果在 EyeofcloudDecision 对象中返回,并包含传递标帜规则所需的所有数据。
请参阅分桶方法decide

决定全部

返回用户的所有活动(未存档)标帜的决策。
请参阅分桶方法decide

决定键

返回指定标帜键的标帜决策映射。
参见[决定方法])doc:decide-methods-javascript)

trackEvent

Tracks a conversion event (in other words, an action a user takes) for a user. Logs an error message if the specified event key doesn't match any existing events.
See Track Event

setForcedDecision

Forces a user into a specific variation.
See Set Forced Decision

getForcedDecision

Returns what variation the user was forced into.
See Get Forced Decision

removeForcedDecision

Removes a user from a specific forced variation.
See Remove Forced Decision

removeAllForcedDecisions

Removes a user from all forced variations.
See Remove All Forced Decisions

See Also

Create User Context

Source files

The language/platform source files containing the implementation for JavaScript Node SDK is eyeofcloud/index.tsopen in new window.

Updated 2 months ago


[

Updating usage from older versions

](/experimentation/v4.0.0-full-stack/docs/migrate-from-older-versions-javascript-node)[

Forced Decision methods

](/experimentation/v4.0.0-full-stack/docs/forced-decision-methods-javascript-node)

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