diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs index f47b21a..d9ddfe0 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs @@ -130,14 +130,19 @@ namespace Guru public static void SetCurrentScreen(string screenName, string className) { + if (!_isInitOnce) + { + return; + } + Log.I(TAG,$"SetCurrentScreen -> screenName:{screenName}, className:{className}"); GuruAnalytics.Instance.SetScreen(screenName); - - if (!IsReady) return; - FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventScreenView, - new Parameter(FirebaseAnalytics.ParameterScreenClass, className), - new Parameter(FirebaseAnalytics.ParameterScreenName, screenName) - ); + + TrackEvent(EventScreenView, new Dictionary() + { + [ParameterScreenName] = screenName, + [ParameterScreenClass] = className, + }); } #endregion @@ -159,15 +164,40 @@ namespace Guru /// /// Firebase上报用户属性 /// - public static void SetUserProperty(string propertyName, string propertyValue) + public static void SetUserProperty(string key, string value) { - Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}"); - - if (!IsReady) - return; + if (!_isInitOnce) + { + throw new Exception($"[{TAG}][SDK] Analytics did not initialized, Call first!"); + } + + if (IsDebug && !EnableDebugAnalytics) + { + Debug.LogWarning($"[{TAG}][SDK] --- SetProperty {key}:{value} can not send int Debug mode. Set with `true`"); + return; + } + + try + { + // 填充相关的追踪事件 + _guruEventDriver.AddProperty(key, value); + _firebaseEventDriver.AddProperty(key, value); + Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{key}, propertyValue:{value}"); + } + catch (Exception ex) + { + if (FirebaseUtil.IsReady) + { + Crashlytics.LogException(ex); + } + else + { + Debug.Log($"Catch Error: {ex}"); + } + } + + - FirebaseAnalytics.SetUserProperty(propertyName, propertyValue); - CustomSetUserProperty(propertyName, propertyValue); } #endregion @@ -207,19 +237,19 @@ namespace Guru // 填充相关的追踪事件 if (eventSetting.EnableGuruAnalytics) { - _guruEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority)); + _guruEventDriver.AddEvent(eventName, data, eventSetting, priority); } if (eventSetting.EnableFirebaseAnalytics) { - _firebaseEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority)); + _firebaseEventDriver.AddEvent(eventName, data, eventSetting, priority); } if (eventSetting.EnableAdjustAnalytics) { - _adjustEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority)); + _adjustEventDriver.AddEvent(eventName, data, eventSetting, priority); } if (eventSetting.EnableFacebookAnalytics) { - _fbEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority)); + _fbEventDriver.AddEvent(eventName, data, eventSetting, priority); } } catch (Exception ex) @@ -318,60 +348,9 @@ namespace Guru #endregion - #region 打点缓存 - - private static Queue _savedLogs; - - internal static Queue SavedLogs - { - get - { - if (_savedLogs == null) _savedLogs = new Queue(20); - return _savedLogs; - } - } - - #endregion - } - public class TrackingEvent - { - public string eventName; - public int priority; - public Dictionary data; - public Analytics.EventSetting setting; - - public TrackingEvent() - { - } - - /// - /// 保存打点信息 - /// - /// - /// - /// - /// - public TrackingEvent(string eventName, Dictionary data = null, Analytics.EventSetting setting = null, int priority = -1) - { - this.eventName = eventName; - this.data = data; - this.setting = setting; - this.priority = priority; - } - - - public void Flush() - { - Analytics.TrackEvent(eventName, data, setting, priority); - } - - public override string ToString() - { - return $"eventName: {eventName}, data: {data}, setting: {setting}, priority: {priority}"; - } - } + } \ No newline at end of file diff --git a/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs b/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs index dc67d0b..b2236b9 100644 --- a/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs +++ b/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs @@ -16,6 +16,8 @@ namespace Guru.Network private const string NETWORK_STATUS_ETHERNET = "ethernet"; private const string NETWORK_STATUS_VPN = "vpn"; private const string NETWORK_STATUS_TETHER = "tether"; + private const string NETWORK_STATUS_BLUETOOTH = "bluetooth"; + private const string NETWORK_STATUS_OTHER = "other"; private bool _isReady = false; @@ -46,17 +48,20 @@ namespace Guru.Network } + /// + /// 网络状态列表 + /// private List _statusNameList = new List() { - NETWORK_STATUS_NONE, - NETWORK_STATUS_ETHERNET, - NETWORK_STATUS_WIFI, - NETWORK_STATUS_MOBILE, NETWORK_STATUS_VPN, - NETWORK_STATUS_TETHER + NETWORK_STATUS_TETHER, + NETWORK_STATUS_MOBILE, + NETWORK_STATUS_WIFI, + NETWORK_STATUS_ETHERNET, + NETWORK_STATUS_BLUETOOTH, + NETWORK_STATUS_OTHER, + NETWORK_STATUS_NONE, }; - - public void Init(Action onInitComplete = null) { @@ -85,7 +90,7 @@ namespace Guru.Network statusName = _statusNameList[i]; if (status.Contains(statusName)) { - Debug.Log($"{Tag} --- GetNetworkStatus : {statusName}"); + Debug.Log($"{Tag} --- GetNetworkStatus: [{string.Join(",", status)}]"); return statusName; } }