fix: 自打点 Firebase ID 赋值优化, 整合到初始化函数内, 不再外部单独赋值

Signed-off-by: huyufei <yufei.hu@castbox.fm>
胡宇飞 2024-08-03 18:40:11 +08:00
parent c73aa0cd96
commit 52f2700c37
2 changed files with 23 additions and 7 deletions

View File

@ -105,24 +105,30 @@ namespace Guru
/// <summary>
/// 初始化接口
/// </summary>
public static void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
public static void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false, string firebaseId = "")
{
Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialing...");
if (_instance == null)
{
_instance = new GuruAnalytics();
bool enableErrorLog = false;
string groupId = "not_set";
#if UNITY_ANDROID
enableErrorLog = true;
// 获取云控参数
// TODO: 针对 GuruSDK 整体的云控值做一个分组的解决方案
var guruInitParams = GuruAnalyticsConfigManager.GetInitParams();
// 记录分组数据
groupId = guruInitParams.groupId;
if (!string.IsNullOrEmpty(firebaseId))
{
// 设置 Firebase ID
_instance.Agent?.SetFirebaseId(firebaseId);
}
if (guruInitParams.enabled && Instance.Agent is AnalyticsAgentAndroid androidAgent)
{
_instance.EnableErrorLog = true;
_instance._experimentGroupId = groupId;
// 强制转换为 Android 的自打点初始化接口
androidAgent.InitAndroidConfig(appId, deviceInfo,
guruInitParams.baseUrl, guruInitParams.uploadIpAddress, // <--- Android 附加参数
@ -134,13 +140,17 @@ namespace Guru
_instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug);
}
#else
_instance.EnableErrorLog = false;
_instance._experimentGroupId = groupId;
// iOS 使用正常的启动接口
_instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug);
#endif
_instance.EnableErrorLog = enableErrorLog;
_instance._experimentGroupId = groupId;
_isReady = true;
Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialized.");
Debug.Log($"{Tag} --- GroupId: {groupId}");
}
}

View File

@ -72,7 +72,7 @@ namespace Guru
/// </summary>
private const string DEFAULT_GURU_ANALYTICS_EXP = @"{
""enable"": true,
""exps"": [{
""experiments"": [{
""groupId"": ""B"",
""baseUrl"": ""https://collect.saas.castbox.fm"",
""uploadIpAddress"": [""13.248.248.135"", ""3.33.195.44""]
@ -144,7 +144,7 @@ namespace Guru
// 最后取不到的话只能默认分组了
if (config == null) {
config = DefaultData.GetFirstConfig(); // 默认是 B 组
if(IsDebug) Debug.LogWarning($"{Tag} --- #3 Try get config is Null -> using Default config");
if(IsDebug) Debug.LogWarning($"{Tag} --- #3.1 Try get config is Null -> using Default config");
}
if (config != null)
@ -153,6 +153,7 @@ namespace Guru
groupId = config.groupId;
uploadIpAddress = config.uploadIpAddress;
LocalExperimentGroupId = groupId;
Debug.LogWarning($"{Tag} --- #3 Using Default config:: baseUrl:{baseUrl} groupId:{groupId} uploadIpAddress:[{ (uploadIpAddress != null ? string.Join(",", uploadIpAddress) : "null")}]");
}
else
{
@ -260,6 +261,11 @@ namespace Guru
public string groupId;
public string baseUrl;
public string[] uploadIpAddress;
public override string ToString()
{
return JsonParser.ToJson(this);
}
}
[Serializable]