从旧变体更新使用情况

云眼About 2 min

从旧变体更新使用情况

本主题介绍如何从旧变体的云眼全栈 PHP SDK 进行更新。

代码示例

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

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

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

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

.PHP

// ------------------------------- // Prereq for new methods: create a user // ------------------------------ $attributes = ['is_logged_in' => true]; $user = $eyeofcloud->createUserContext('user_123', $attributes); // ------------------------------- // Is Feature Enabled // ------------------------------ // old method $enabled = $eyeofcloud->isFeatureEnabled('flag_1', 'user_123', $attributes); // new method $decision = $user->decide('flag_1'); $enabled = $decision->getEnabled(); // ------------------------------- // Activate & Get Variation // ------------------------------ // old method $variationKey = $eyeofcloud->activate('experiment_1', 'user_123', $attributes); // new method $variationKey = $decision->getVariationKey(); // ------------------------------- // Get All Feature Variables // ------------------------------ // old method $allVarValues = $eyeofcloud->getAllFeatureVariables('flag_1', 'user_123', $attributes); // new method $allVarValues = $decision->getVariables(); // ------------------------------- // Get Enabled Features // ------------------------------ // old method $enabledFlags = $eyeofcloud->getEnabledFeatures('user_123'); // new method $decisions = $user->decideAll(['ENABLED_FLAGS_ONLY']); $enabledFlags = array_keys($decisions); // ------------------------------- // Track // ------------------------------ // old method $eyeofcloud->track('my_purchase_event_key', 'user_123', $attributes, ['purchase_count' => 2]); // new method $user->trackEvent('my_purchase_event_key', ['purchase_count' => 2]);

激活方法和A / B测试

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

Last update:
Contributors: “zhangweixue”,zhangweixue