diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs index 92e3938..29fe950 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs @@ -25,7 +25,7 @@ namespace Guru private const string VALUE_ONLY_FOR_IOS = "idfa_only_for_ios"; public static bool IsDebug { get; set; } = false; - private static bool _isGuruAnalyticInitOnce = false; + private static readonly bool _isGuruAnalyticInitOnce = false; public static void InitGuruAnalyticService(GuruAnalyticsInitConfig initConfig, string firebaseId) { @@ -38,7 +38,7 @@ namespace Guru #if UNITY_EDITOR IsDebug = true; #else - IsDebug = isDebug; + IsDebug = initConfig.isDebug; #endif string appId = IPMConfig.IPM_X_APP_ID; string deviceInfo = new DeviceInfoData().ToString(); @@ -54,8 +54,8 @@ namespace Guru if(!string.IsNullOrEmpty(firebaseId)) GuruAnalytics.Instance.SetFirebaseId(firebaseId); // 在自打点初始化之前, 需要调用一下设置 FirebaseId - GuruAnalytics.Init(appId, deviceInfo, initConfig); // Android 初始化 - UpdateAllValues(); + GuruAnalytics.Init(appId, deviceInfo, initConfig, OnGuruAnalyticsInitComplete); // Android 初始化 + UpdateAllUserProperties(); } catch (Exception ex) { @@ -245,9 +245,9 @@ namespace Guru #endif /// - /// 获取全部ID + /// 上报中台打点的用户属性 /// - private static void UpdateAllValues() + private static void UpdateAllUserProperties() { Debug.Log($"{TAG} --- UpdateAllValues"); @@ -296,7 +296,7 @@ namespace Guru try { GuruAnalytics.Instance.SetUserProperty(key, value); - UpdateAllValues(); // 同步所有的ID + UpdateAllUserProperties(); // 同步所有的ID } catch (Exception ex) { @@ -311,32 +311,6 @@ namespace Guru } } - - /// - /// 自定义事件打点 - /// - /// - /// - private static void TrackEventGuru(string key, Dictionary data = null, int priority = -1) - { - try - { - if (data == null) data = new Dictionary(); - GuruAnalytics.Instance.LogEvent(key, data, priority); - UpdateAllValues(); // 同步所有的ID - } - catch (Exception e) - { - if (IsFirebaseReady) - { - Crashlytics.LogException(e); - } - else - { - Debug.LogWarning(e); - } - } - } /// /// 设置太极02阀值 diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs index 2b26e98..c89921e 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs @@ -233,6 +233,8 @@ namespace Guru return; } + + if (eventSetting == null) eventSetting = DefaultEventSetting; var dataStr = ""; diff --git a/Runtime/GuruCore/Runtime/ExtensionKit/NetworkUtil.cs b/Runtime/GuruCore/Runtime/ExtensionKit/NetworkUtil.cs index 051441d..48cf6a7 100644 --- a/Runtime/GuruCore/Runtime/ExtensionKit/NetworkUtil.cs +++ b/Runtime/GuruCore/Runtime/ExtensionKit/NetworkUtil.cs @@ -2,5 +2,5 @@ using UnityEngine; public static class NetworkUtil { - public static bool IsNetAvaliable => Application.internetReachability != NetworkReachability.NotReachable; + public static bool IsNetAvailable => Application.internetReachability != NetworkReachability.NotReachable; } \ No newline at end of file diff --git a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Auth.cs b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Auth.cs index 3ec8834..6ca3e39 100644 --- a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Auth.cs +++ b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Auth.cs @@ -13,8 +13,6 @@ namespace Guru private const float LOGIN_RETRY_MAX_TIME = 60; // 最大请求间隔时间 private const float LOGIN_RETRY_INTERVAL = 10; // 最大请求间隔时间 - - private static float _retryDelayTime = 10; // 登录重试时间 /// @@ -35,49 +33,56 @@ namespace Guru if (string.IsNullOrEmpty(authToken)) authToken = IPMConfig.IPM_FIREBASE_TOKEN; Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}"); - - if (string.IsNullOrEmpty(authToken) || !NetworkUtil.IsNetAvaliable) + + if (!string.IsNullOrEmpty(authToken) && NetworkUtil.IsNetAvailable) { - // Token 为空 或 网络不可用 - if (autoRetry) - { - // 继续重试 - DelayCallFirebaseLogin(Mathf.Min(_retryDelayTime, LOGIN_RETRY_MAX_TIME), onLoginResult, authToken); - _retryDelayTime += LOGIN_RETRY_INTERVAL; // 最大重试间隔 60s - } - else - { - // 不再重试 - onLoginResult?.Invoke(false); - } + + LoginFirebase(authToken, autoRetry, onLoginResult); return; } - FirebaseAuth.DefaultInstance.SignInWithCustomTokenAsync(authToken) - .ContinueWithOnMainThread(task => - { - // ----- Task failed ----- - if (task.IsCanceled || task.IsFaulted) - { - Log.E(LOG_TAG,"[Auth] SignInWithCustomTokenAsync encountered an error: " + task.Exception); - if (autoRetry) - { - DelayCallFirebaseLogin(_retryDelayTime, onLoginResult, authToken); // 自动重试 - } - else - { - onLoginResult?.Invoke(false); // 不再重试 - } - return; - } - // ----- Check Result ----- - bool success = FirebaseUser != null; - onLoginResult?.Invoke(success); - _retryDelayTime = LOGIN_RETRY_INTERVAL; - }); + // Token 为空 或 网络不可用 + if (autoRetry) + { + // 继续重试 + DelayCallFirebaseLogin(Mathf.Min(_retryDelayTime, LOGIN_RETRY_MAX_TIME), onLoginResult, authToken); + _retryDelayTime += LOGIN_RETRY_INTERVAL; // 最大重试间隔 60s + } + else + { + // 不再重试 + onLoginResult?.Invoke(false); + } } + private static void LoginFirebase(string authToken = "", bool autoRetry = true, Action onLoginResult = null) + { + FirebaseAuth.DefaultInstance.SignInWithCustomTokenAsync(authToken) + .ContinueWithOnMainThread(task => + { + // ----- Task failed ----- + if (task.IsCanceled || task.IsFaulted) + { + Log.E(LOG_TAG,"[Auth] SignInWithCustomTokenAsync encountered an error: " + task.Exception); + if (autoRetry) + { + DelayCallFirebaseLogin(_retryDelayTime, onLoginResult, authToken); // 自动重试 + } + else + { + onLoginResult?.Invoke(false); // 不再重试 + } + return; + } + // ----- Check Result ----- + bool success = FirebaseUser != null; + onLoginResult?.Invoke(success); + _retryDelayTime = LOGIN_RETRY_INTERVAL; + }); + } + + // TODO:P0 协程不应该用在此场景 /// /// 延迟调用 Firebase 登录请求 /// diff --git a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Message.cs b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Message.cs index 53ab10a..68e28a7 100644 --- a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Message.cs +++ b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.Message.cs @@ -65,7 +65,7 @@ namespace Guru private static void UploadDeviceInfo() { - if (!NetworkUtil.IsNetAvaliable) + if (!NetworkUtil.IsNetAvailable) { double retryDelay = Math.Pow(2, _messageRetry); _messageRetry++;