从旧变体更新使用情况

云眼About 2 min

从旧变体更新使用情况

本主题介绍如何从旧变体的云眼全栈 C# SDK 更新到云眼灰度发布(特性标帜)AB实验。

代码示例

本节提供了代码示例,说明我们建议如何利用新的决策和事件跟踪 API。所有现有方法和实现仍包含在内并受支持,并且只有在弃用标记和未来主要变体后才会删除。

我们建议采用新的“决定”、“全部决定”和“跟踪事件”方法,作为当前在实现中使用 isFeatureEnabled、getFeatureVariable、getAllFeatures或 Track 调用的更灵活、更易于使用的替代方法。

有关早期方法,请参阅 SDK 参考指南的早期变体open in new window

下面是如何将旧方法迁移到较新方法的一些示例。

C#

// ------------------------------- // Prereq for new methods: create a user // ------------------------------ UserAttributes attributes = new UserAttributes(); attributes.Add("is_logged_in", true); EyeofcloudUserContext user = eyeofcloud.CreateUserContext("user_123", attributes); // ------------------------------- // Is Feature Enabled // ------------------------------ // old method bool enabled = eyeofcloud.IsFeatureEnabled("flag_1", "user_123", attributes); // new method EyeofcloudDecision decision = user.Decide("flag_1"); bool enabled = decision.Enabled; // ------------------------------- // Activate & Get Variation // ------------------------------ // old method Variation variation = eyeofcloud.Activate("experiment_1", "user_123", attributes); // new method string variationKey = decision.VariationKey; // ------------------------------- // Get All Feature Variables // ------------------------------ // old method EyeofcloudJSON json = eyeofcloud.GetAllFeatureVariables("flag_1", "user_123", attributes); // new method var json = decision.Variables; // ------------------------------- // Get Enabled Features // ------------------------------ // old method var enabledFlags = eyeofcloud.GetEnabledFeatures("user_123", attributes); // new method var options = new EyeofcloudDecideOption[] { EyeofcloudDecideOption.ENABLED_FLAGS_ONLY }; var decisions = user.DecideAll(options); var enabledFlags = decisions.Keys; // ------------------------------- // Track // ------------------------------ // old method var tags = new EventTags{ { "revenue", 42 } }; attributes.Add("purchase_count", 2); eyeofcloud.Track("my_purchase_event_key", "user_123", attributes, tags); // new method user.TrackEvent("my_purchase_event_key", tags);

激活方法和A / B测试

与现有的“已启用功能”方法一样,“决定”方法基于灰度发布(特性标帜)键,不支持独立的 A/B 测试或多臂 Bandit。我们正在努力长期统一应用程序的数据模型和接口,以减少维护多种不同访问方法的需求。同时,仍然可以在旧项目中使用“激活”和“获取变体”方法以及“决定”方法进行独立的 A/B 测试。

Last update:
Contributors: “zhangweixue”