fix: 优化实验策略,数据读取逻辑
--story=1021087 --user=yufei.hu 【中台】【自打点】升级自打点原生库至 1.1.1,并在 Water1 中落地验证 https://www.tapd.cn/33527076/s/1159023 Signed-off-by: huyufei <yufei.hu@castbox.fm>hotfix/v1.0.12.2
parent
6dd2574763
commit
9de443249d
|
|
@ -58,7 +58,7 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 默认的本地配置
|
||||
/// </summary>
|
||||
public static string DEFAULT_GURU_ANALYTICS_EXP = @"{
|
||||
private static string DEFAULT_GURU_ANALYTICS_EXP = @"{
|
||||
""enable"": true,
|
||||
""exps"": [{
|
||||
""groupId"": ""B"",
|
||||
|
|
@ -94,10 +94,9 @@ namespace Guru
|
|||
string localGroup = "";
|
||||
string remoteGroup = "";
|
||||
GuruAnalyticsExpData expData = null;
|
||||
bool usingLocalData = false;
|
||||
GuruAnalyticsExpConfig config = null;
|
||||
|
||||
var gid = SavedGuruAnalyticsExpGroupId;
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #0 Analytics EXP saved groupId :{gid}");
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #0 Analytics EXP saved groupId :{SavedGuruAnalyticsExpGroupId}");
|
||||
|
||||
// 拉取云控数据
|
||||
var json = "";
|
||||
|
|
@ -106,47 +105,68 @@ namespace Guru
|
|||
|
||||
if (string.IsNullOrEmpty(json))
|
||||
{
|
||||
// 没有云控值,走本地的数据配置,随机取值
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #1 Analytics EXP json is Null -> using DefaultData");
|
||||
expData = DefaultData;
|
||||
usingLocalData = true;
|
||||
config = GetDefaultGuruAnalyticsExpConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #2 Analytics EXP Try to get remote json -> {json}");
|
||||
expData = Parse(json);
|
||||
usingLocalData = false;
|
||||
}
|
||||
|
||||
GuruAnalyticsExpConfig config = null;
|
||||
if (string.IsNullOrEmpty(gid))
|
||||
if (expData == null)
|
||||
{
|
||||
config = expData.GetRandomConfig();
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #3 no group Id, get random one: id: {config?.groupId ?? "NULL"}");
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #2.1 Analytics EXP Parse failed -> using DefaultData");
|
||||
config = GetDefaultGuruAnalyticsExpConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
config = expData.GetConfig(gid);
|
||||
if (config == null)
|
||||
if (!expData.enable)
|
||||
{
|
||||
config = expData.GetRandomConfig();
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #4 Get old Config failed: {gid}, change to random: id: {config?.groupId ?? "NULL"}");
|
||||
Debug.LogWarning($"{Tag} --- #2.2 Analytics EXP Disabled -> using DefaultData");
|
||||
expData = DefaultData;
|
||||
}
|
||||
config = expData.GetFirstConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (config == null) {
|
||||
config = DefaultData.exps[0]; // 默认是 B 组
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #6 Get all config is Null -> using Default config B");
|
||||
config = DefaultData.GetFirstConfig(); // 默认是 B 组
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #3 Try get config is Null -> using Default config");
|
||||
}
|
||||
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
baseUrl = config.baseUrl;
|
||||
groupId = config.groupId;
|
||||
uploadIpAddress = config.uploadIpAddress;
|
||||
SavedGuruAnalyticsExpGroupId = groupId;
|
||||
}
|
||||
else
|
||||
{
|
||||
isEnable = false;
|
||||
}
|
||||
|
||||
Debug.Log($"{Tag} --- Analytics EXP params:: groupId:{groupId} baseUrl:{baseUrl} uploadIpAddress:[{string.Join(",", uploadIpAddress)}]");
|
||||
}
|
||||
|
||||
|
||||
private static GuruAnalyticsExpConfig GetDefaultGuruAnalyticsExpConfig()
|
||||
{
|
||||
GuruAnalyticsExpConfig config = null;
|
||||
if (!string.IsNullOrEmpty(SavedGuruAnalyticsExpGroupId))
|
||||
{
|
||||
config = DefaultData.GetConfig(SavedGuruAnalyticsExpGroupId); // 非空则取值
|
||||
}
|
||||
else
|
||||
{
|
||||
config = DefaultData.GetRandomConfig(); // 随机获取本地的 Config
|
||||
}
|
||||
if(IsDebug) Debug.LogWarning($"{Tag} --- #1.1 using Default GropId: {config?.groupId ?? "NULL"}");
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 实验数据主题
|
||||
|
|
@ -182,6 +202,16 @@ namespace Guru
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取首个配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public GuruAnalyticsExpConfig GetFirstConfig()
|
||||
{
|
||||
if (exps != null && exps.Length > 0) return exps[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分组是否存在
|
||||
|
|
@ -202,7 +232,7 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 实验配置
|
||||
/// </summary>
|
||||
public class GuruAnalyticsExpConfig
|
||||
internal class GuruAnalyticsExpConfig
|
||||
{
|
||||
public string groupId;
|
||||
public string baseUrl;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
|
@ -57,7 +59,6 @@ namespace Guru
|
|||
/// </summary>
|
||||
private static void InitializeFirebaseComp()
|
||||
{
|
||||
InitGuruAnalyticsExpDefaultRemoteValue(); // 提前注入云控参数默认值
|
||||
InitCrashlytics(); // 老项目沿用此逻辑
|
||||
InitRemoteConfig(); // 老项目沿用此逻辑
|
||||
InitAssetByFirebaseIdAsync(); // 获取到 FirebaseID 后异步执行逻辑
|
||||
|
|
@ -153,7 +154,6 @@ namespace Guru
|
|||
// Firebase 初始化才能调用此方法
|
||||
private static void InitAnalytics()
|
||||
{
|
||||
|
||||
#if UNITY_ANDROID
|
||||
// Android 平台开始
|
||||
var fid = IPMConfig.FIREBASE_ID;// 获取 FirebaseID
|
||||
|
|
@ -162,35 +162,18 @@ namespace Guru
|
|||
// 随机抽取本地分组获取数据
|
||||
GuruAnalyticsExp.GetGuruAnalyticsExpParams(out string groupId, out string baseUrl, out string[] uploadIpAddress, out bool isEnable);
|
||||
|
||||
// 自打点启动前,先上报一下分数数据
|
||||
GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, groupId); // 设置实验分组
|
||||
|
||||
// 初始化打点和自打点
|
||||
Analytics.InitAnalytics(baseUrl, uploadIpAddress, isEnable, enableErrorLog, fid); // 打点提前初始化
|
||||
Analytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, groupId); // 上报分组数据
|
||||
#else
|
||||
|
||||
// iOS 不参与分组
|
||||
GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, "none");
|
||||
Analytics.InitAnalytics();
|
||||
Analytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, "none"); // 上报分组数据
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID
|
||||
|
||||
// 添加默认的云控参数
|
||||
private static void InitGuruAnalyticsExpDefaultRemoteValue()
|
||||
{
|
||||
// AppendDefaultValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, GuruAnalyticsExp.DEFAULT_GURU_ANALYTICS_EXP);
|
||||
FirebaseRemoteConfig.DefaultInstance.SetDefaultsAsync(new Dictionary<string, object>()
|
||||
{
|
||||
{ GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, GuruAnalyticsExp.DEFAULT_GURU_ANALYTICS_EXP }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue