云眼用户上下文
2024年10月10日大约 2 分钟
云眼用户上下文
本主题介绍 EyeofcloudUserContext 对象,该对象允许为 Eyeofcloud 灰度标帜(Feature Flag) Harmony SDK 的用户上下文做出标帜决策并跟踪事件。
以下代码显示了 EyeofcloudUserContext 的对象定义:
interface EyeofcloudUserContext {
  // return user attributes
  getAttributes(): UserAttributes;
  // set an attribute for the user 
  setAttribute(key: string, value: unknown): void;
  // 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 对象的属性:
| 属性 | 类型 | 评论 | 
|---|---|---|
| userId | String | 用户的ID | 
| attributes (可选) | UserAttributes | 自定义键值对的映射,用于指定用于受众群体定位的用户属性。创建用户时,可以使用用户 ID 传递映射。 | 
方法
下表显示了 EyeofcloudUserContext 对象的方法:
| 方法 | 评论 | 
|---|---|
| setAttribute | 将自定义用户属性作为键值对传递给用户上下文。 | 
| decide | 返回用户的标帜键的决策结果。决策结果在 EyeofcloudDecision 对象中返回,并包含传递标帜规则所需的所有数据请参阅分桶方法decide | 
| decideAll | 返回用户的所有活动(未存档)标帜的决策。请参阅分桶方法decide | 
| decideForKeys | 返回指定标帜键的标帜决策映射。 | 
| trackEvent | 跟踪用户的转化事件(即用户执行的操作)。如果指定的事件键与任何现有事件不匹配,则记录错误消息。 查看跟踪事件 | 
| setForcedDecision | 强制用户使用特定变体。 请参阅设置强制决策 | 
| getForcedDecision | 返回用户被强制进入的变体。 请参阅获取强制决策 | 
| removeForcedDecision | 从特定的强制变体中删除用户。 请参阅删除强制决策 | 
| removeAllForcedDecisions | 从所有强制变体中移除用户。 请参阅删除所有强制决策 | 
源文件
包含Harmony SDK实现的语言/平台源文件是Harmony-SDK