从旧变体更新使用情况

云眼About 2 min

从旧变体更新使用情况

本文介绍如何从旧版云眼全栈 Android SDK 更新到云眼灰度实验

代码示例

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

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

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

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

KotlinJava

// Prereq for new methods: create a user val attributes: MutableMap<String, Any?> = HashMap() attributes["is_logged_in"] = true val user = eyeofcloudClient.createUserContext("user123", attributes) // Is Feature Enabled // old method var enabled = eyeofcloudClient.isFeatureEnabled("flag_1", "user123", attributes) // new method val decision = user!!.decide("flag_1") enabled = decision.enabled // Activate & Get Variation // old method val variation = eyeofcloudClient.activate("experiment_1", "user123", attributes) // new method val variationKey = decision.variationKey // Get All Feature Variables // old method var json = eyeofcloudClient.getAllFeatureVariables("flag_1", "user123", attributes) // new method json = decision.variables // Get Enabled Features // old method val enabledFlags = eyeofcloudClient.getEnabledFeatures("user123", attributes) // new method val options = Arrays.asList(EyeofcloudDecideOption.ENABLED_FLAGS_ONLY) val decisions = user.decideAll(options) val enabledFlagsSet: Set<String> = decisions.keys // Track // old method val tags: Map<String, Any?> = HashMap() attributes["purchase_count"] = 2 eyeofcloudClient.track("my_purchase_event_key", "user123", attributes, tags) // new method user.trackEvent("my_purchase_event_key", tags)

// Prereq for new methods: create a user Map<String, Object> attributes = new HashMap<>(); attributes.put("is_logged_in", true); EyeofcloudUserContext user = eyeofcloudClient.createUserContext("user123", attributes); // Is Feature Enabled // old method boolean enabled = eyeofcloudClient.isFeatureEnabled("flag_1", "user123", attributes); // new method EyeofcloudDecision decision = user.decide("flag_1"); enabled = decision.getEnabled(); // Activate & Get Variation // old method Variation variation = eyeofcloudClient.activate("experiment_1", "user123", attributes); // new method String variationKey = decision.getVariationKey(); // Get All Feature Variables // old method EyeofcloudJSON json = eyeofcloudClient.getAllFeatureVariables("flag_1", "user123", attributes); // new method json = decision.getVariables(); // Get Enabled Features // old method List<String> enabledFlags = eyeofcloudClient.getEnabledFeatures("user123", attributes); // new method List<EyeofcloudDecideOption> options = Arrays.asList(EyeofcloudDecideOption.ENABLED_FLAGS_ONLY); Map<String, EyeofcloudDecision> decisions = user.decideAll(options); Set<String> enabledFlagsSet = decisions.keySet(); // Track // old method Map<String, Object> tags = new HashMap<>(); attributes.put("purchase_count", 2); eyeofcloudClient.track("my_purchase_event_key", "user123", attributes, tags); // new method user.trackEvent("my_purchase_event_key", tags);

激活方法和A / B测试

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

Last update:
Contributors: zhangweixue,“zhangweixue”