云眼用户上下文
May 11, 2023About 3 min
云眼用户上下文
本主题介绍 EyeofcloudUserContext 对象,该对象允许为 Eyeofcloud 功能实验 Python SDK 的用户上下文做出标帜决策并跟踪事件。
对象允许做出标帜决策并跟踪已使用创建用户上下文方法创建的用户上下文的事件。
云眼用户上下文变体
EyeofcloudUserContext 在 SDK v3.8.0 及更高版本上受支持。
强制决策方法变体
set_forced_decision()
、get_forced_decision()
、remove_forced_decision()
和remove_all_forced_decision()
方法在 4.0.0 及更高版本上受支持。
云眼用户上下文定义
以下代码显示了 EyeofcloudUserContext 的对象定义:
Python
class EyeofcloudUserContext(object):
# set an attribute for the user
def set_attribute(self, attribute_key, attribute_value):
# get attributes for the user
def get_user_attributes(self):
# make a decision about which flag variation the user buckets into for the flag key
def decide(self, key, options=None):
# make decisions about which flag variations the user buckets into for flag keys
def decide_for_keys(self, keys, options=None):
# make decisions about which flag variations the user buckets into for all flags
def decide_all(self, options=None):
# track user event
def track_event(self, event_key, event_tags=None):
# EyeofcloudDecisionContext
class EyeofcloudDecisionContext(object):
def __init__(self, flag_key, rule_key):
# EyeofcloudForcedDecision
class EyeofcloudForcedDecision(object):
def __init__(self, variation_key):
# Sets the forced decision (variation_key) for a given decision context
def set_forced_decision(self, EyeofcloudDecisionContext, EyeofcloudForcedDecision):
# Returns the forced decision for a given decision context
def get_forced_decision(self, EyeofcloudDecisionContext):
# Removes the forced decision for a given decision context
def remove_forced_decision(self, EyeofcloudDecisionContext):
# Removes all forced decisions bound to this user context
def remove_all_forced_decisions(self):
性能
下表显示了 EyeofcloudUserContext 对象的属性:
属性 | 类型 | 评论 |
---|---|---|
user_id | 字符串 | 用户的 ID |
(可选)属性 | Map | 自定义键值对的映射,用于指定用于受众群体定位的用户属性。创建用户时,可以使用用户 ID 传递映射。 |
方法
下表显示了 EyeofcloudUserContext 对象的方法:
方法 | 评论 |
---|---|
set_attribute | 将自定义用户属性作为键值对传递给用户上下文。 |
决定 | 返回用户的标帜键的决策结果。决策结果在 EyeofcloudDecision 对象中返回,并包含传递标帜规则所需的所有数据。 请参阅分桶方法decide |
decide_for_keys | 返回指定标帜键的标帜决策映射。 请参阅分桶方法decide |
decide_all | 返回用户的所有活动(未存档)标帜的决策。 请参阅分桶方法decide |
track_event | 跟踪用户的转化事件(即用户执行的操作)。如果指定的事件键与任何现有事件不匹配,则记录错误消息。 查看跟踪事件 |
set_forced_decision | 强制用户使用特定变体。 请参阅设置强制决策 |
get_forced_decision | 返回用户被强制进入的变体。 请参阅获取强制决策 |
remove_forced_decision | 从特定的强制变体中删除用户。 请参阅删除强制决策 |
remove_all_forced_decisions | 从所有强制变体中移除用户。 请参阅删除所有强制决策 |
参见
源文件
包含 Python 实现的语言/平台源文件 eyeofcloud.py。