update: 更新打包日志,完善云控参数读取, 重构本地测试逻辑, 规范日志

Signed-off-by: huyufei <yufei.hu@castbox.fm>
hotfix/v1.0.12.2
胡宇飞 2024-07-24 10:35:27 +08:00
parent bd39fb09f1
commit 6dd2574763
10 changed files with 235 additions and 80 deletions

View File

@ -8,18 +8,20 @@ Sample Dependencies.xml:
<androidPackage spec="androidx.core:core:1.7.0" /> <androidPackage spec="androidx.core:core:1.7.0" />
<!-- <androidPackage spec="androidx.appcompat:appcompat:1.5.1" />--> <!-- <androidPackage spec="androidx.appcompat:appcompat:1.5.1" />-->
<androidPackage spec="androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" /> <androidPackage spec="androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" />
<androidPackage spec="androidx.work:work-runtime:2.7.1" /> <androidPackage spec="androidx.work:work-runtime:2.9.0" />
<androidPackage spec="androidx.work:work-runtime-ktx:2.7.1" /> <androidPackage spec="androidx.work:work-runtime-ktx:2.9.0" />
<androidPackage spec="androidx.work:work-rxjava2:2.7.1" /> <androidPackage spec="androidx.work:work-rxjava2:2.9.0" />
<androidPackage spec="androidx.lifecycle:lifecycle-process:2.4.0" /> <androidPackage spec="androidx.lifecycle:lifecycle-process:2.4.0" />
<androidPackage spec="com.jakewharton.timber:timber:4.7.1" /> <androidPackage spec="com.jakewharton.timber:timber:4.7.1" />
<androidPackage spec="com.google.code.gson:gson:2.8.5" /> <androidPackage spec="com.google.code.gson:gson:2.8.5" />
<androidPackage spec="androidx.room:room-runtime:2.4.3" /> <androidPackage spec="androidx.room:room-runtime:2.6.1" />
<androidPackage spec="androidx.room:room-rxjava2:2.4.3" /> <androidPackage spec="androidx.room:room-rxjava2:2.6.1" />
<androidPackage spec="com.squareup.retrofit2:retrofit:2.7.1" /> <androidPackage spec="com.squareup.retrofit2:retrofit:2.7.1" />
<androidPackage spec="com.squareup.retrofit2:converter-gson:2.7.1" /> <androidPackage spec="com.squareup.retrofit2:converter-gson:2.7.1" />
<androidPackage spec="com.squareup.retrofit2:adapter-rxjava2:2.7.1" /> <androidPackage spec="com.squareup.retrofit2:adapter-rxjava2:2.7.1" />
<androidPackage spec="com.squareup.okhttp3:okhttp:4.9.3" /> <androidPackage spec="com.squareup.okhttp3:okhttp:4.12.0" />
<androidPackage spec="com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0" />
<androidPackage spec="com.google.net.cronet:cronet-okhttp:0.1.0" />
<!-- <androidPackage spec="com.mapzen:on-the-road:0.8.1" />--> <!-- <androidPackage spec="com.mapzen:on-the-road:0.8.1" />-->
<!-- <androidPackage spec="com.squareup.retrofit2:retrofit:2.7.1" />--> <!-- <androidPackage spec="com.squareup.retrofit2:retrofit:2.7.1" />-->
</androidPackages> </androidPackages>

View File

@ -1,16 +1,37 @@
namespace Guru namespace Guru
{ {
using Guru;
using System; using System;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
using System.Collections.Generic; using Firebase.RemoteConfig;
using System.Linq;
public class GuruAnalyticsExp public class GuruAnalyticsExp
{ {
private const string Tag = "[SDK][ANU][EXP]";
private static bool IsDebug
{
get
{
#if UNITY_EDITOR || DEBUG
return true;
#endif
return false;
}
}
private static string SavedGuruAnalyticsExpGroupId
{
get => PlayerPrefs.GetString(nameof(SavedGuruAnalyticsExpGroupId), "");
set
{
PlayerPrefs.SetString(nameof(SavedGuruAnalyticsExpGroupId), value);
PlayerPrefs.Save();
}
}
/** /**
* *
private const string JSON_GROUP_B = private const string JSON_GROUP_B =
@ -25,7 +46,7 @@ namespace Guru
/// </summary> /// </summary>
/// <param name="json"></param> /// <param name="json"></param>
/// <returns></returns> /// <returns></returns>
public static GuruAnalyticsExpData Parse(string json) private static GuruAnalyticsExpData Parse(string json)
{ {
if (string.IsNullOrEmpty(json)) return null; if (string.IsNullOrEmpty(json)) return null;
return JsonParser.ToObject<GuruAnalyticsExpData>(json); return JsonParser.ToObject<GuruAnalyticsExpData>(json);
@ -50,24 +71,132 @@ namespace Guru
}] }]
}"; }";
public static GuruAnalyticsExpData DefaultData => Parse(DEFAULT_GURU_ANALYTICS_EXP); /// <summary>
/// 获取默认数据
/// </summary>
private static GuruAnalyticsExpData DefaultData => Parse(DEFAULT_GURU_ANALYTICS_EXP);
/// <summary>
/// 在当前版本中,随机获取线上配置的值
/// 若无法获取线上配置,则默认是 B 分组
/// </summary>
/// <param name="groupId"></param>
/// <param name="baseUrl"></param>
/// <param name="uploadIpAddress"></param>
/// <param name="isEnable"></param>
public static void GetGuruAnalyticsExpParams(out string groupId, out string baseUrl, out string[] uploadIpAddress, out bool isEnable)
{
groupId = "";
baseUrl = "";
uploadIpAddress = null;
isEnable = true;
string localGroup = "";
string remoteGroup = "";
GuruAnalyticsExpData expData = null;
bool usingLocalData = false;
var gid = SavedGuruAnalyticsExpGroupId;
if(IsDebug) Debug.LogWarning($"{Tag} --- #0 Analytics EXP saved groupId :{gid}");
// 拉取云控数据
var json = "";
if(FirebaseUtil.IsFirebaseInitialized && FirebaseRemoteConfig.DefaultInstance.Keys.Contains(KEY_GURU_ANALYTICS_EXP))
json = FirebaseRemoteConfig.DefaultInstance.GetValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP).StringValue;
if (string.IsNullOrEmpty(json))
{
if(IsDebug) Debug.LogWarning($"{Tag} --- #1 Analytics EXP json is Null -> using DefaultData");
expData = DefaultData;
usingLocalData = true;
}
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))
{
config = expData.GetRandomConfig();
if(IsDebug) Debug.LogWarning($"{Tag} --- #3 no group Id, get random one: id: {config?.groupId ?? "NULL"}");
}
else
{
config = expData.GetConfig(gid);
if (config == null)
{
config = expData.GetRandomConfig();
if(IsDebug) Debug.LogWarning($"{Tag} --- #4 Get old Config failed: {gid}, change to random: id: {config?.groupId ?? "NULL"}");
}
}
if (config == null) {
config = DefaultData.exps[0]; // 默认是 B 组
if(IsDebug) Debug.LogWarning($"{Tag} --- #6 Get all config is Null -> using Default config B");
}
baseUrl = config.baseUrl;
groupId = config.groupId;
uploadIpAddress = config.uploadIpAddress;
SavedGuruAnalyticsExpGroupId = groupId;
Debug.Log($"{Tag} --- Analytics EXP params:: groupId:{groupId} baseUrl:{baseUrl} uploadIpAddress:[{string.Join(",", uploadIpAddress)}]");
}
} }
/// <summary> /// <summary>
/// 实验数据主题 /// 实验数据主题
/// </summary> /// </summary>
public class GuruAnalyticsExpData internal class GuruAnalyticsExpData
{ {
public bool enable = true; // 默认是打开的状态 public bool enable = true; // 默认是打开的状态
public GuruAnalyticsExpConfig[] exps; // 实验列表 public GuruAnalyticsExpConfig[] exps; // 实验列表
public string ToJson() => JsonParser.ToJson(this); // 转换成 JSON 字符串 public string ToJson() => JsonParser.ToJson(this); // 转换成 JSON 字符串
/// <summary>
/// 获取随机分组
/// </summary>
/// <returns></returns>
public GuruAnalyticsExpConfig GetRandomConfig() public GuruAnalyticsExpConfig GetRandomConfig()
{ {
if (exps == null || exps.Length == 0) return null; if (exps == null || exps.Length == 0) return null;
return exps[Random.Range(0, exps.Length)]; return exps[Random.Range(0, exps.Length)];
} }
/// <summary>
/// 根据分组名称获取分组
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public GuruAnalyticsExpConfig GetConfig(string groupId)
{
foreach (var g in exps)
{
if (g.groupId == groupId) return g;
}
return null;
}
/// <summary>
/// 分组是否存在
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public bool IsGroupExists(string groupId)
{
foreach (var g in exps)
{
if (g.groupId == groupId) return true;
}
return false;
}
} }
/// <summary> /// <summary>
@ -77,7 +206,7 @@ namespace Guru
{ {
public string groupId; public string groupId;
public string baseUrl; public string baseUrl;
public List<string> uploadIpAddress; public string[] uploadIpAddress;
} }
} }

View File

@ -105,7 +105,7 @@ namespace Guru
/// <param name="isEnable"></param> /// <param name="isEnable"></param>
/// <param name="enableErrorLog"></param> /// <param name="enableErrorLog"></param>
/// <param name="isDebug"></param> /// <param name="isDebug"></param>
public static void InitWithConfig(string appId, string deviceInfo, string baseUrl, List<string> uploadIpAddress, bool isEnable = true, bool enableErrorLog = true, bool isDebug = false) public static void InitWithConfig(string appId, string deviceInfo, string baseUrl, string[] uploadIpAddress, bool isEnable = true, bool enableErrorLog = true, bool isDebug = false)
{ {
_enableErrorLog = enableErrorLog; _enableErrorLog = enableErrorLog;
#if UNITY_ANDROID #if UNITY_ANDROID

View File

@ -88,7 +88,7 @@ namespace Guru
bool useWorker = true; bool useWorker = true;
bool useCronet = false; bool useCronet = false;
string baseUrl = ""; string baseUrl = "";
List<string> uploadIpAddress = null; string[] uploadIpAddress = null;
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, isDebug); // 调用接口 CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, isDebug); // 调用接口
} }
@ -101,7 +101,7 @@ namespace Guru
/// <param name="baseUrl"></param> /// <param name="baseUrl"></param>
/// <param name="uploadIpAddress"></param> /// <param name="uploadIpAddress"></param>
/// <param name="isDebug"></param> /// <param name="isDebug"></param>
public void InitWithConfig(string appId, string deviceInfo, string baseUrl, List<string> uploadIpAddress, bool isDebug = false) public void InitWithConfig(string appId, string deviceInfo, string baseUrl, string[]uploadIpAddress, bool isDebug = false)
{ {
_isDebug = isDebug; _isDebug = isDebug;
string bundleId = Application.identifier; string bundleId = Application.identifier;
@ -125,12 +125,12 @@ namespace Guru
string deviceInfo, string deviceInfo,
string bundleId, string bundleId,
string baseUrl = "", string baseUrl = "",
List<string> uploadIpAddress = null, string[] uploadIpAddress = null,
bool useWorker = true, bool useWorker = true,
bool useCronet = false, bool useCronet = false,
bool isDebug = false) bool isDebug = false)
{ {
CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, uploadIpAddress); // 调用接口 CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, string.Join(",", uploadIpAddress)); // 调用接口
} }

View File

@ -39,11 +39,13 @@ namespace Guru
} }
public static void InitGuruAnalyticService(string baseUrl, List<string> uploadIpAddress, bool isEnable = true, bool isDebug = false, public static void InitGuruAnalyticService(string baseUrl, string[] uploadIpAddress, bool isEnable = true, bool isDebug = false,
bool enableErrorLog = false, string firebaseId = "") bool enableErrorLog = false, string firebaseId = "")
{ {
if (_hasInited) return; if (_hasInited) return;
Debug.Log($"{TAG} --- InstallGuruAnalytics baseUrl: {baseUrl} enableErrorLog: {enableErrorLog} firebaseId:{firebaseId}");
try try
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
@ -89,7 +91,7 @@ namespace Guru
{ {
Debug.Log($"---[ANA] UID: {IPMConfig.IPM_UID}"); Debug.Log($"---[ANA] UID: {IPMConfig.IPM_UID}");
GuruAnalytics.SetUid(IPMConfig.IPM_UID); GuruAnalytics.SetUid(IPMConfig.IPM_UID);
FirebaseAnalytics.SetUserProperty(PropertyUserID, IPMConfig.IPM_UID); FirebaseSetUserProperty(PropertyUserID, IPMConfig.IPM_UID);
_hasGotUid = true; _hasGotUid = true;
} }
@ -105,7 +107,7 @@ namespace Guru
if (!string.IsNullOrEmpty(IPMConfig.IPM_DEVICE_ID)) if (!string.IsNullOrEmpty(IPMConfig.IPM_DEVICE_ID))
{ {
GuruAnalytics.SetDeviceId(IPMConfig.IPM_DEVICE_ID); GuruAnalytics.SetDeviceId(IPMConfig.IPM_DEVICE_ID);
FirebaseAnalytics.SetUserProperty(PropertyDeviceID, IPMConfig.IPM_DEVICE_ID); FirebaseSetUserProperty(PropertyDeviceID, IPMConfig.IPM_DEVICE_ID);
_hasGotDeviceId = true; _hasGotDeviceId = true;
} }
} }
@ -194,6 +196,8 @@ namespace Guru
/// </summary> /// </summary>
private static void FetchFirebaseId() private static void FetchFirebaseId()
{ {
if (!IsFirebaseReady) return;
FirebaseAnalytics.GetAnalyticsInstanceIdAsync() FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
.ContinueWithOnMainThread(task => .ContinueWithOnMainThread(task =>
{ {
@ -259,6 +263,8 @@ namespace Guru
/// </summary> /// </summary>
private static void UpdateAllValues() private static void UpdateAllValues()
{ {
Debug.Log($"{TAG} --- UpdateAllValues");
SetUid(); SetUid();
SetDeviceId(); SetDeviceId();
SetAdjustId(); SetAdjustId();
@ -306,9 +312,16 @@ namespace Guru
GuruAnalytics.SetUserProperty(key, value); GuruAnalytics.SetUserProperty(key, value);
UpdateAllValues(); // 同步所有的ID UpdateAllValues(); // 同步所有的ID
} }
catch (Exception e) catch (Exception ex)
{ {
Crashlytics.LogException(e); if (IsFirebaseReady)
{
Crashlytics.LogException(ex);
}
else
{
Debug.LogException(ex);
}
} }
} }
@ -328,7 +341,14 @@ namespace Guru
} }
catch (Exception e) catch (Exception e)
{ {
Crashlytics.LogException(e); if (IsFirebaseReady)
{
Crashlytics.LogException(e);
}
else
{
Debug.LogWarning(e);
}
} }
} }
@ -352,7 +372,14 @@ namespace Guru
} }
catch (Exception e) catch (Exception e)
{ {
Crashlytics.LogException(e); if (IsFirebaseReady)
{
Crashlytics.LogException(e);
}
else
{
Debug.LogWarning(e);
}
} }
} }

View File

@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using UnityEngine;
namespace Guru namespace Guru
{ {
@ -28,12 +29,14 @@ namespace Guru
public static bool IsDebugMode => PlatformUtil.IsDebug(); public static bool IsDebugMode => PlatformUtil.IsDebug();
public static bool IsFirebaseReady => FirebaseUtil.IsFirebaseInitialized;
private static bool IsEnable private static bool IsEnable
{ {
get get
{ {
//Firebase服务没有初始化完成不上报打点 //Firebase服务没有初始化完成不上报打点
if (!FirebaseUtil.IsFirebaseInitialized) if (!IsFirebaseReady)
return false; return false;
//Analytics没有初始化不上报打点 //Analytics没有初始化不上报打点
@ -50,7 +53,7 @@ namespace Guru
#region 初始化 #region 初始化
public static void InitAnalytics(string baseUrl = "", List<string> uploadIpAddress = null, bool isEnable = false, bool enableErrorLog = false, string firebaseId = "") public static void InitAnalytics(string baseUrl = "", string[] uploadIpAddress = null, bool isEnable = false, bool enableErrorLog = false, string firebaseId = "")
{ {
if (_isInited) return; if (_isInited) return;
_isInited = true; _isInited = true;
@ -121,8 +124,7 @@ namespace Guru
{ {
Log.I(TAG,$"SetUserIDProperty -> userID:{userID}"); Log.I(TAG,$"SetUserIDProperty -> userID:{userID}");
if (!IsEnable) return; if (!IsEnable) return;
if (IsFirebaseReady) FirebaseAnalytics.SetUserId(userID);
FirebaseAnalytics.SetUserId(userID);
} }
/// <summary> /// <summary>
@ -132,13 +134,30 @@ namespace Guru
{ {
Log.I(TAG,$"SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}"); Log.I(TAG,$"SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}");
if (!IsEnable) if (!IsEnable) return;
return; FirebaseSetUserProperty(propertyName, propertyValue);
FirebaseAnalytics.SetUserProperty(propertyName, propertyValue);
CustomSetUserProperty(propertyName, propertyValue); CustomSetUserProperty(propertyName, propertyValue);
} }
/// <summary>
/// Firebase 上报用户属性
/// </summary>
/// <param name="propertyName"></param>
/// <param name="propertyValue"></param>
private static void FirebaseSetUserProperty(string propertyName, string propertyValue)
{
if (IsFirebaseReady)
{
FirebaseAnalytics.SetUserProperty(propertyName, propertyValue);
}
else
{
Debug.Log($"{TAG} --- Firebase not ready, call Firebase Init first!");
}
}
#endregion #endregion
#region 打点上报 #region 打点上报
@ -375,7 +394,7 @@ namespace Guru
} }
catch (Exception ex) catch (Exception ex)
{ {
Crashlytics.LogException(ex); if(IsFirebaseReady) Crashlytics.LogException(ex);
} }
} }

View File

@ -5,6 +5,8 @@ namespace Guru
{ {
public static partial class FirebaseUtil public static partial class FirebaseUtil
{ {
public static void InitCrashlytics() public static void InitCrashlytics()
{ {
if(!string.IsNullOrEmpty(IPMConfig.IPM_UID)) if(!string.IsNullOrEmpty(IPMConfig.IPM_UID))
@ -17,6 +19,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetUserID(string userID) public static void SetUserID(string userID)
{ {
if (!IsFirebaseInitialized) return;
Crashlytics.SetUserId(userID); Crashlytics.SetUserId(userID);
} }
@ -26,6 +29,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetCustomData(string key, string value) public static void SetCustomData(string key, string value)
{ {
if (!IsFirebaseInitialized) return;
Crashlytics.SetCustomKey(key, value); Crashlytics.SetCustomKey(key, value);
} }
@ -34,6 +38,7 @@ namespace Guru
/// </summary> /// </summary>
public static void LogMessage(string message) public static void LogMessage(string message)
{ {
if (!IsFirebaseInitialized) return;
Crashlytics.Log(message); Crashlytics.Log(message);
} }
@ -42,6 +47,7 @@ namespace Guru
/// </summary> /// </summary>
public static void LogException(Exception exception) public static void LogException(Exception exception)
{ {
if (!IsFirebaseInitialized) return;
Crashlytics.LogException(exception); Crashlytics.LogException(exception);
} }
} }

View File

@ -14,7 +14,7 @@ namespace Guru
private static readonly string LOG_TAG = "Firebase"; private static readonly string LOG_TAG = "Firebase";
private static bool _isDebug = false; private static bool _isDebug = false;
private static bool _isReady = false; private static bool _isReady = false;
public static bool IsReady => _isReady; public static bool IsReady => _isReady && IsFirebaseInitialized;
public static DependencyStatus DependencyStatus = DependencyStatus.UnavailableOther; public static DependencyStatus DependencyStatus = DependencyStatus.UnavailableOther;
public static bool IsFirebaseInitialized => DependencyStatus == DependencyStatus.Available; public static bool IsFirebaseInitialized => DependencyStatus == DependencyStatus.Available;
@ -106,6 +106,9 @@ namespace Guru
private static void InitAssetByFirebaseIdAsync() private static void InitAssetByFirebaseIdAsync()
{ {
Debug.Log($"[SDK] --- InitAssetByFirebaseIdAsync");
// 异步获取 FirebaseID // 异步获取 FirebaseID
FirebaseAnalytics.GetAnalyticsInstanceIdAsync() FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
.ContinueWithOnMainThread(task => .ContinueWithOnMainThread(task =>
@ -115,12 +118,12 @@ namespace Guru
{ {
// 保存本地ID备份 // 保存本地ID备份
IPMConfig.FIREBASE_ID = fid; // 保存FirebaseID IPMConfig.FIREBASE_ID = fid; // 保存FirebaseID
Debug.Log($"[SDk] --- Get FirebaseID: {fid}"); Debug.Log($"[SDK] --- Get FirebaseID: {fid}");
GuruAnalytics.SetFirebaseId(fid); GuruAnalytics.SetFirebaseId(fid);
} }
else else
{ {
Debug.LogError($"[SDk] --- Fetch FirebaseID failed on start!"); Debug.LogError($"[SDK] --- Fetch FirebaseID failed on start!");
} }
//--- 结束后启动相关的服务 --- //--- 结束后启动相关的服务 ---
@ -157,7 +160,7 @@ namespace Guru
var enableErrorLog = true; // 开启日志上报 var enableErrorLog = true; // 开启日志上报
// 随机抽取本地分组获取数据 // 随机抽取本地分组获取数据
GetGuruAnalyticsExpConfig(out string groupId, out string baseUrl, out List<string> uploadIpAddress, out bool isEnable); GuruAnalyticsExp.GetGuruAnalyticsExpParams(out string groupId, out string baseUrl, out string[] uploadIpAddress, out bool isEnable);
// 自打点启动前,先上报一下分数数据 // 自打点启动前,先上报一下分数数据
GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, groupId); // 设置实验分组 GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, groupId); // 设置实验分组
@ -178,45 +181,14 @@ namespace Guru
// 添加默认的云控参数 // 添加默认的云控参数
private static void InitGuruAnalyticsExpDefaultRemoteValue() private static void InitGuruAnalyticsExpDefaultRemoteValue()
{ {
AppendDefaultValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, GuruAnalyticsExp.DEFAULT_GURU_ANALYTICS_EXP); // 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 }
});
} }
/// <summary>
/// 在当前版本中,随机获取线上配置的值
/// 若无法获取线上配置,则默认是 B 分组
/// </summary>
/// <param name="groupId"></param>
/// <param name="baseUrl"></param>
/// <param name="uploadIpAddress"></param>
/// <param name="isEnable"></param>
private static void GetGuruAnalyticsExpConfig(out string groupId, out string baseUrl, out List<string> uploadIpAddress, out bool isEnable)
{
groupId = "";
baseUrl = "";
uploadIpAddress = null;
isEnable = true;
// 如果云测关闭
var json = FirebaseRemoteConfig.DefaultInstance.GetValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP).StringValue;
var expData = GuruAnalyticsExp.Parse(json);
var defaultExpData = GuruAnalyticsExp.DefaultData;
GuruAnalyticsExpConfig config = null;
if (expData == null)
{
config = defaultExpData.exps[0]; // 默认是 B 组
}
else
{
config = expData.GetRandomConfig();
if (config == null) config = defaultExpData.exps[0]; // 默认是 B 组
}
baseUrl = config.baseUrl;
groupId = config.groupId;
uploadIpAddress = config.uploadIpAddress;
Debug.Log($"[SDK][ANU] --- Analytics EXP Group: {groupId} baseUrl:{baseUrl} uploadIpAddress:[{string.Join(",", uploadIpAddress)}]");
}
#endif #endif
#endregion #endregion

View File

@ -101,7 +101,7 @@ namespace Guru
public static void LogException(Exception ex) public static void LogException(Exception ex)
{ {
if (!_isReady) if (!_isReady || !FirebaseUtil.IsReady)
{ {
Install(); Install();
_expCache.Enqueue(ex); _expCache.Enqueue(ex);
@ -119,7 +119,7 @@ namespace Guru
public static void Log(string msg) public static void Log(string msg)
{ {
if (!_isReady) return; if (!_isReady) return;
Crashlytics.Log(msg); if(FirebaseUtil.IsReady) Crashlytics.Log(msg);
// CheckSetUser(); // CheckSetUser();
} }
@ -127,7 +127,7 @@ namespace Guru
public static void SetCustomKey(string key, string value) public static void SetCustomKey(string key, string value)
{ {
if (!_isReady) return; if (!_isReady) return;
Crashlytics.SetCustomKey(key, value); if(FirebaseUtil.IsReady) Crashlytics.SetCustomKey(key, value);
} }