fix: 修改 setUID 调用混乱导致的自打点初始化异常。 从而导致自打点上报失败
Signed-off-by: huyufei <yufei.hu@castbox.fm>
							parent
							
								
									d7f41bbba6
								
							
						
					
					
						commit
						acff632c8b
					
				|  | @ -19,19 +19,20 @@ namespace Guru | |||
| 		public const string K_SUB_PURCHASE = "sub_purchase"; // 固定点位事件 | ||||
| 
 | ||||
| 		private static Action<string> _onInitComplete; | ||||
| 		 | ||||
| 		private static Action<string> _onGetGoogleAdidHandler; | ||||
| 
 | ||||
| 		private static string _adId = ""; | ||||
| 		public static string AdId | ||||
| 		private static string _googleAdId = ""; | ||||
| 		public static string GoogleAdId // GPS = Google Play Service | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
| 				if(string.IsNullOrEmpty(_adId)) FetchGoogleAdId(); | ||||
| 				return _adId; // Google AdId | ||||
| 				if(string.IsNullOrEmpty(_googleAdId)) FetchGoogleAdIdAsync(); | ||||
| 				return _googleAdId; // Google AdId | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		public static string IDFA => Adjust.getIdfa(); | ||||
| 		public static string IDFV => Adjust.getIdfv(); | ||||
| 
 | ||||
| 		private static string _adjustId = ""; | ||||
| 		public static string AdjustId | ||||
|  | @ -53,12 +54,13 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		/// <param name="appToken"></param> | ||||
| 		/// <param name="fbAppId">MIR 追踪 AppID</param> | ||||
| 		/// <param name="firebaseId"></param> | ||||
| 		/// <param name="deviceId"></param> | ||||
| 		/// <param name="onInitComplete">初始化完成的时候会返回 AdjustId </param> | ||||
| 		/// <param name="onDeeplinkCallback"></param> | ||||
| 		/// <param name="firebaseId"></param> | ||||
| 		/// <param name="onGetGoogleAdIdCallback"></param> | ||||
| 		public static void StartService(string appToken, string fbAppId = "", string firebaseId = "", string deviceId = "",  | ||||
| 			Action<string> onInitComplete = null, Action<string> onDeeplinkCallback = null) | ||||
| 			Action<string> onInitComplete = null, Action<string> onDeeplinkCallback = null, Action<string> onGetGoogleAdIdCallback = null) | ||||
| 		{ | ||||
| 			if (string.IsNullOrEmpty(appToken)) | ||||
| 			{ | ||||
|  | @ -67,6 +69,7 @@ namespace Guru | |||
| 			} | ||||
| 
 | ||||
| 			_onInitComplete = onInitComplete; | ||||
| 			_onGetGoogleAdidHandler = onGetGoogleAdIdCallback; | ||||
| 
 | ||||
| 			InstallEvent(firebaseId, deviceId); // 注入启动参数 | ||||
| 
 | ||||
|  | @ -79,13 +82,11 @@ namespace Guru | |||
| 			 | ||||
| 			if(onDeeplinkCallback != null) | ||||
| 				config.setDeferredDeeplinkDelegate(onDeeplinkCallback); | ||||
|              | ||||
| 
 | ||||
| 			 | ||||
| #if UNITY_ANDROID | ||||
| 			if (!string.IsNullOrEmpty(fbAppId)) config.setFbAppId(fbAppId); // 注入 MIR ID | ||||
| #endif | ||||
| 			 | ||||
| 
 | ||||
| #if UNITY_EDITOR || DEBUG | ||||
| 			config.setLogDelegate(log => LogI(LOG_TAG, log)); | ||||
| 			config.setEventSuccessDelegate(OnEventSuccessCallback); | ||||
|  | @ -98,18 +99,22 @@ namespace Guru | |||
| 			Adjust.start(config); | ||||
| 			 | ||||
| 			// 异步加载AdId | ||||
| 			FetchGoogleAdId(); | ||||
| 			FetchGoogleAdIdAsync(); | ||||
| 
 | ||||
| 			LogI(LOG_TAG, $"----- Start AdjustService[{Version}]  AdjustVer:{AdjustVersion} -----"); | ||||
| 		} | ||||
| 
 | ||||
| 		public static void FetchGoogleAdId() | ||||
| 		/// <summary> | ||||
| 		/// 异步拉取 Google Ad Id | ||||
| 		/// </summary> | ||||
| 		private static void FetchGoogleAdIdAsync() | ||||
| 		{ | ||||
| 			Adjust.getGoogleAdId(gid => | ||||
| 			{ | ||||
| 				if (!string.IsNullOrEmpty(gid)) | ||||
| 				{ | ||||
| 					_adId = gid; // 获取Google AD ID  | ||||
| 					_googleAdId = gid; // 获取Google AD ID  | ||||
| 					_onGetGoogleAdidHandler?.Invoke(_googleAdId); // 返回 GSADID | ||||
| 				} | ||||
| 			}); | ||||
| 		} | ||||
|  | @ -130,9 +135,6 @@ namespace Guru | |||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		 | ||||
| 		 | ||||
| 		 | ||||
| 		#endregion | ||||
| 		 | ||||
| 		#region 关键属性上报 | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ namespace Guru | |||
|             { | ||||
|                 if (_instance == null) | ||||
|                 { | ||||
|                     throw new Exception("GuruAnalytics not initialized. Please call <Analytics.InitAnalytics()> first."); | ||||
|                     _instance = new GuruAnalytics(); | ||||
|                 } | ||||
|                 return _instance; | ||||
|             } | ||||
|  | @ -105,55 +105,50 @@ namespace Guru | |||
|         /// <summary> | ||||
|         /// 初始化接口 | ||||
|         /// </summary> | ||||
|         public static void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false, string firebaseId = "") | ||||
|         public 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(); | ||||
|                 string groupId = "not_set"; | ||||
|             if (_isReady) return; | ||||
|              | ||||
|             string groupId = "not_set"; | ||||
| #if UNITY_ANDROID | ||||
|                 // 获取云控参数 | ||||
|                 // 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 附加参数 | ||||
|                         onInitComplete, isDebug); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // 外部(云控)如果关闭使用 Android 自打点附加参数, 则使用正常的启动接口 | ||||
|                     _instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
|                 } | ||||
| #else | ||||
|                 _instance.EnableErrorLog = false; | ||||
|                 _instance._experimentGroupId = groupId; | ||||
|                 // iOS 使用正常的启动接口 | ||||
|                 _instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
| #endif            | ||||
|                  | ||||
| 
 | ||||
|                 _isReady = true; | ||||
|                  | ||||
|                 Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialized."); | ||||
|                 Debug.Log($"{Tag} --- GroupId: {groupId}"); | ||||
|             // 获取云控参数 | ||||
|             // 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 附加参数 | ||||
|                     onInitComplete, isDebug); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // 外部(云控)如果关闭使用 Android 自打点附加参数, 则使用正常的启动接口 | ||||
|                 Instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
|             } | ||||
| #else | ||||
|             Instance.EnableErrorLog = false; | ||||
|             Instance._experimentGroupId = groupId; | ||||
|             // iOS 使用正常的启动接口 | ||||
|             Instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
| #endif            | ||||
|              | ||||
|             _isReady = true; | ||||
|             Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialized."); | ||||
|             Debug.Log($"{Tag} --- GroupId: {groupId}"); | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// 设置视图名称 | ||||
|  | @ -161,8 +156,9 @@ namespace Guru | |||
|         /// <param name="screenName"></param> | ||||
|         public void SetScreen(string screenName) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(screenName)) return; | ||||
|             CacheUserProperty($"screen_name", screenName); | ||||
|             // CacheUserProperty($"screen_name", screenName); | ||||
|             Agent.SetScreen(screenName); | ||||
|         } | ||||
| 
 | ||||
|  | @ -172,8 +168,9 @@ namespace Guru | |||
|         /// <param name="id"></param> | ||||
|         public void SetAdId(string id) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(id)) return; | ||||
|             CacheUserProperty($"ad_id", id); | ||||
|             // CacheUserProperty($"ad_id", id); | ||||
|             Agent.SetAdId(id); | ||||
|         } | ||||
| 
 | ||||
|  | @ -184,8 +181,9 @@ namespace Guru | |||
|         /// <param name="value"></param> | ||||
|         public void SetUserProperty(string key, string value) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return; | ||||
|             CacheUserProperty(key, value); // 添加用户属性 | ||||
|             // CacheUserProperty(key, value); // 添加用户属性 | ||||
|             // ReSharper disable once Unity.PerformanceCriticalCodeInvocation | ||||
|             Agent.SetUserProperty(key, value); | ||||
|         } | ||||
|  | @ -195,8 +193,9 @@ namespace Guru | |||
|         /// <param name="id"></param> | ||||
|         public void SetFirebaseId(string id) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(id)) return; | ||||
|             CacheUserProperty($"firebase_id", id); | ||||
|             // CacheUserProperty($"firebase_id", id); | ||||
|             Agent.SetFirebaseId(id); | ||||
|         } | ||||
| 
 | ||||
|  | @ -206,8 +205,9 @@ namespace Guru | |||
|         /// <param name="id"></param> | ||||
|         public void SetAdjustId(string id) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(id)) return; | ||||
|             CacheUserProperty($"adjust_id", id); | ||||
|             // CacheUserProperty($"adjust_id", id); | ||||
|             Agent.SetAdjustId(id); | ||||
|         } | ||||
| 
 | ||||
|  | @ -217,28 +217,32 @@ namespace Guru | |||
|         /// <param name="deviceId"></param> | ||||
|         public void SetDeviceId(string deviceId) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(deviceId)) return; | ||||
|             CacheUserProperty($"device_id", deviceId); | ||||
|             // CacheUserProperty($"device_id", deviceId); | ||||
|             Agent.SetDeviceId(deviceId); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void SetAndroidID(string androidId) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(androidId)) return; | ||||
|             CacheUserProperty(Analytics.PropertyAndroidID, androidId); | ||||
|             // CacheUserProperty(Analytics.PropertyAndroidID, androidId); | ||||
|         } | ||||
|          | ||||
|         public void SetIDFV(string idfv) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(idfv)) return; | ||||
|             CacheUserProperty(Analytics.PropertyIDFV, idfv); | ||||
|             // CacheUserProperty(Analytics.PropertyIDFV, idfv); | ||||
|         } | ||||
|          | ||||
|         public void SetIDFA(string idfa) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(idfa)) return; | ||||
|             CacheUserProperty(Analytics.PropertyIDFA, idfa); | ||||
|             // CacheUserProperty(Analytics.PropertyIDFA, idfa); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -248,8 +252,9 @@ namespace Guru | |||
|         /// <param name="uid"></param> | ||||
|         public void SetUid(string uid) | ||||
|         { | ||||
|             if (!_isReady) return; | ||||
|             if (string.IsNullOrEmpty(uid)) return; | ||||
|             CacheUserProperty($"uid", uid); | ||||
|             // CacheUserProperty($"uid", uid); | ||||
|             Agent.SetUid(uid); | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,12 +11,14 @@ namespace Guru | |||
|     /// </summary> | ||||
|     public partial class Analytics | ||||
|     { | ||||
| 	    private static bool _hasGotFirebaseId;  //已取得FirebaseId | ||||
| 	    private static bool _hasGotAdId; // 已取得AdId | ||||
| 	    private static bool _hasGotIDFA; // 已取得IDFA | ||||
| 	    private static bool _hasGotAdjustId; // 已取得AdjustId | ||||
| 	    private static bool _hasGotDeviceId; // 已取得DeviceId | ||||
| 	    private static bool _hasGotUid; // 已取得UID | ||||
| 	    private static bool _hasSetFirebaseId;  //已取得FirebaseId | ||||
| 	    private static bool _hasSetAdId; // 已取得AdId | ||||
| 	    private static bool _hasSetIDFA; // 已取得IDFA | ||||
| 	    private static bool _hasSetAdjustId; // 已取得AdjustId | ||||
| 	    private static bool _hasSetDeviceId; // 已取得DeviceId | ||||
| 	    private static bool _hasSetUid; // 已取得UID | ||||
| 	    private static bool _hasSetIDFV;  // 已经取得 IDFV | ||||
| 	    private static bool _hasSetAndroidId; // 已取得AndroidId | ||||
| 	    private static DateTime _lastReportRateDate; //上次上报信息的日期 | ||||
| 	    private static double _reportSuccessInterval; // 上报频率 | ||||
| #if UNITY_IOS | ||||
|  | @ -36,23 +38,24 @@ namespace Guru | |||
| 			    string appId = IPMConfig.IPM_X_APP_ID; | ||||
| 			    string deviceInfo = new DeviceInfoData().ToString(); | ||||
| 
 | ||||
| 			    _hasGotFirebaseId = false; | ||||
| 			    _hasGotAdId = false; | ||||
| 			    _hasGotAdjustId = false; | ||||
| 			    _hasGotDeviceId = false; | ||||
| 			    _hasGotUid = false; | ||||
| 			    _hasSetFirebaseId = false; | ||||
| 			    _hasSetAdId = false; | ||||
| 			    _hasSetAdjustId = false; | ||||
| 			    _hasSetDeviceId = false; | ||||
| 			    _hasSetUid = false; | ||||
| 			    _lastReportRateDate = DateTime.Now; | ||||
| 			    _reportSuccessInterval = 120; // 2分钟上报一次 | ||||
| 
 | ||||
| 			    Debug.Log($"{TAG} [guru_analytic] --- InitGuruAnalyticService: IsDebug:{IsDebug}  firebaseId:{firebaseId}"); | ||||
| 			     | ||||
| 			    GuruAnalytics.Init(appId, deviceInfo, () => | ||||
| 			    GuruAnalytics.Instance.Init(appId, deviceInfo, () => | ||||
| 			    { | ||||
| 				    OnGuruAnalyticsInitComplete(); | ||||
| 				    Debug.Log($"{TAG} [guru_analytic]--- Guru EXP: GroupId: {GuruAnalytics.Instance.ExperimentGroupId}"); | ||||
| 				    SetUserProperty(GuruAnalyticsConfigManager.KEY_GURU_ANALYTICS_EXP, GuruAnalytics.Instance.ExperimentGroupId); | ||||
| 				    ApplyAllUserProperties(); | ||||
| 			    }, IsDebug, firebaseId); // Android 初始化	 | ||||
| 			    UpdateAllUserProperties(); | ||||
| 			     | ||||
| 		    } | ||||
| 		    catch (Exception ex) | ||||
| 		    { | ||||
|  | @ -66,57 +69,42 @@ namespace Guru | |||
| 		/// <summary> | ||||
| 		/// 设置用户ID | ||||
| 		/// </summary> | ||||
| 		private static void SetUid() | ||||
| 		public static void SetUid(string uid) | ||||
| 		{ | ||||
| 			if (_hasGotUid) return; | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.IPM_UID)) | ||||
| 			{ | ||||
| 				Debug.Log($"---[ANA] UID: {IPMConfig.IPM_UID}"); | ||||
| 				GuruAnalytics.Instance.SetUid(IPMConfig.IPM_UID); | ||||
| 				FirebaseAnalytics.SetUserProperty(PropertyUserID, IPMConfig.IPM_UID); | ||||
| 				_hasGotUid = true; | ||||
| 			} | ||||
| 
 | ||||
| 			if (_hasSetUid) return; | ||||
| 			if (string.IsNullOrEmpty(uid)) return; | ||||
| 			Debug.Log($"---[ANA] UID: {uid}"); | ||||
| 			GuruAnalytics.Instance.SetUid(uid); | ||||
| 			FirebaseAnalytics.SetUserId(uid); | ||||
| 			_hasSetUid = true; | ||||
| 		} | ||||
| 
 | ||||
| 		/// <summary> | ||||
| 		/// 设置设备ID | ||||
| 		/// </summary> | ||||
| 		private static void SetDeviceId() | ||||
| 		private static void SetDeviceId(string deviceId) | ||||
| 		{ | ||||
| 			if (_hasGotDeviceId) return; | ||||
| 			if (_hasSetDeviceId) return; | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.IPM_DEVICE_ID)) | ||||
| 			if (!string.IsNullOrEmpty(deviceId)) | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetDeviceId(IPMConfig.IPM_DEVICE_ID); | ||||
| 				FirebaseAnalytics.SetUserProperty(PropertyDeviceID, IPMConfig.IPM_DEVICE_ID); | ||||
| 				_hasGotDeviceId = true; | ||||
| 				GuruAnalytics.Instance.SetDeviceId(deviceId); | ||||
| 				FirebaseAnalytics.SetUserProperty(PropertyDeviceID, deviceId); | ||||
| 				_hasSetDeviceId = true; | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		/// <summary> | ||||
| 		/// 设置 AdjustId  | ||||
| 		/// </summary> | ||||
| 		private static void SetAdjustId() | ||||
| 		private static void SetAdjustId(string adjustId) | ||||
| 		{ | ||||
| 			if (_hasGotAdjustId) return; | ||||
| 			if (_hasSetAdjustId) return; | ||||
| 
 | ||||
| #if UNITY_EDITOR | ||||
| 			string adjustId = "editor_fake_adjust_id"; | ||||
| #else | ||||
| 			string adjustId = AdjustService.AdjustId; | ||||
| #endif | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(adjustId)) | ||||
| 			{ | ||||
| 				IPMConfig.ADJUST_ID = adjustId; | ||||
| 			} | ||||
| 
 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID)) | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetAdjustId(IPMConfig.ADJUST_ID); | ||||
| 				_hasGotAdjustId = true; | ||||
| 				GuruAnalytics.Instance.SetAdjustId(adjustId); | ||||
| 				_hasSetAdjustId = true; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
|  | @ -128,28 +116,14 @@ namespace Guru | |||
| 		/// <summary> | ||||
| 		/// 设置 AdId | ||||
| 		/// </summary> | ||||
| 		private static void SetAdId() | ||||
| 		private static void SetAdId(string adId) | ||||
| 		{ | ||||
| 			if (_hasGotAdId) return; | ||||
| 			 | ||||
| #if UNITY_ANDROID | ||||
| 			var adId = AdjustService.AdId; | ||||
| 			if (!string.IsNullOrEmpty(adId)) | ||||
| 			{ | ||||
| 				// Debug.Log($"---[ANA] ADID: {adId}"); | ||||
| 				IPMConfig.ADJUST_ADID = adId; | ||||
| 			} | ||||
| #else | ||||
| 			// ============= ADID is not supported on Adjust iOS API ============== | ||||
| 			IPMConfig.ADJUST_ADID = VALUE_NOT_FOR_IOS;; | ||||
| #endif | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ADID)) | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetAdId(IPMConfig.ADJUST_ADID); | ||||
| 				_hasGotAdId = true; | ||||
| 			} | ||||
| 			 | ||||
| 			if (_hasSetAdId) return; | ||||
| 
 | ||||
| 			if (string.IsNullOrEmpty(adId)) return; | ||||
| 			GuruAnalytics.Instance.SetAdId(adId); | ||||
| 			_hasSetAdId = true; | ||||
| 
 | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
|  | @ -159,18 +133,14 @@ namespace Guru | |||
| 		/// <summary> | ||||
| 		/// 设置FirebaseId | ||||
| 		/// </summary> | ||||
| 		private static void SetFirebaseId() | ||||
| 		private static void SetFirebaseId(string firebaseId) | ||||
| 		{ | ||||
| 			if (_hasGotFirebaseId) return; | ||||
| 			if (_hasSetFirebaseId) return; | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.FIREBASE_ID)) | ||||
| 			if (!string.IsNullOrEmpty(firebaseId)) | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetFirebaseId(IPMConfig.FIREBASE_ID); | ||||
| 				_hasGotFirebaseId = true; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				FetchFirebaseId(); | ||||
| 				GuruAnalytics.Instance.SetFirebaseId(firebaseId); | ||||
| 				_hasSetFirebaseId = true; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
|  | @ -200,68 +170,70 @@ namespace Guru | |||
| 	    /// <summary> | ||||
| 	    /// 更新ATT状态 (Only IOS 有效) | ||||
| 	    /// </summary> | ||||
| 	    private static void SetATTStatus() | ||||
| 	    private static void ApplyATTStatus() | ||||
| 	    { | ||||
| 		    string status = ATTManager.GetStatus(); | ||||
| 		    GuruAnalytics.Instance.SetUserProperty(ParameterATTStatus, status); | ||||
| 	    } | ||||
| 
 | ||||
| 	    private static void SetIDFV() | ||||
| 	    private static void SetIDFV(string idfv) | ||||
| 	    { | ||||
| 		    GuruAnalytics.Instance.SetIDFV(DeviceIDHelper.IDFV); | ||||
| 			if(_hasSetIDFV) return; | ||||
| 		    if (string.IsNullOrEmpty(idfv)) return; | ||||
| 		    GuruAnalytics.Instance.SetIDFV(idfv); | ||||
| 			_hasSetIDFV = true; | ||||
| 	    } | ||||
| 
 | ||||
| 		private static void SetIDFA() | ||||
| 		private static void SetIDFA(string idfa) | ||||
| 		{ | ||||
| 			if(_hasGotIDFA) return; | ||||
| 			var idfa = AdjustService.IDFA; | ||||
| 
 | ||||
| 			if (!string.IsNullOrEmpty(idfa)) | ||||
| 			{ | ||||
| 				// Debug.Log($"---[ANA] ADID: {adId}"); | ||||
| 				IPMConfig.ADJUST_IDFA = idfa; | ||||
| 			} | ||||
| 			 | ||||
| 			if (!string.IsNullOrEmpty(IPMConfig.ADJUST_IDFA)) | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetIDFA(IPMConfig.ADJUST_IDFA); | ||||
| 				_hasGotIDFA = true; | ||||
| 			} | ||||
| 			if(_hasSetIDFA) return; | ||||
| 			if (string.IsNullOrEmpty(idfa)) return; | ||||
| 			GuruAnalytics.Instance.SetIDFA(idfa); | ||||
| 			_hasSetIDFA = true; | ||||
| 		} | ||||
| 	     | ||||
| #endif | ||||
| 
 | ||||
| #if UNITY_ANDROID  | ||||
| 		/// <summary> | ||||
| 	    /// 更新 Android ID 的参数 | ||||
| 	    /// </summary> | ||||
| 	    private static void SetAndroidId() | ||||
| 	    private static void SetAndroidId(string androidId) | ||||
| 	    { | ||||
| 		    GuruAnalytics.Instance.SetAndroidID(DeviceIDHelper.AndroidID); | ||||
| 		    if (_hasSetAndroidId) return; | ||||
| 		    if (string.IsNullOrEmpty(androidId)) return; | ||||
| 		    GuruAnalytics.Instance.SetAndroidID(androidId); | ||||
| 		    _hasSetAndroidId = true; | ||||
| 	    } | ||||
| #endif	     | ||||
| 	     | ||||
| 		/// <summary> | ||||
| 		/// 上报中台打点的用户属性 | ||||
| 		/// </summary> | ||||
| 		private static void UpdateAllUserProperties() | ||||
| 		private static void ApplyAllUserProperties() | ||||
| 		{ | ||||
| 			 | ||||
| 			Debug.Log($"{TAG} --- UpdateAllValues"); | ||||
| 			SetUid(); | ||||
| 			SetDeviceId(); | ||||
| 			SetAdjustId(); | ||||
| 			SetFirebaseId(); | ||||
| 			SetAdId(); | ||||
| 			SetUid(IPMConfig.IPM_UID); | ||||
| 			SetDeviceId(IPMConfig.IPM_DEVICE_ID); | ||||
| 			SetAdjustId(IPMConfig.ADJUST_ID); | ||||
| 			if (string.IsNullOrEmpty(IPMConfig.FIREBASE_ID)) | ||||
| 			{ | ||||
| 				FetchFirebaseId(); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				SetFirebaseId(IPMConfig.FIREBASE_ID); | ||||
| 			} | ||||
| 			SetAdId(IPMConfig.ADJUST_ADID); | ||||
| 			 | ||||
| #if UNITY_ANDROID | ||||
| 			SetAndroidId(); | ||||
| 			SetAndroidId(DeviceIDHelper.AndroidID); | ||||
| #endif | ||||
| 			 | ||||
| #if UNITY_IOS | ||||
| 			SetATTStatus(); | ||||
| 			SetIDFV(); | ||||
| 			SetIDFA(); | ||||
| 			ApplyATTStatus(); | ||||
| 			SetIDFV(IPMConfig.ADJUST_IDFV); | ||||
| 			SetIDFA(IPMConfig.ADJUST_IDFA); | ||||
| #endif   | ||||
| 			ReportEventSuccessRate(); | ||||
| 		} | ||||
|  | @ -281,34 +253,8 @@ namespace Guru | |||
| 
 | ||||
| 		#endregion | ||||
| 		 | ||||
| 		#region 自定义打点 | ||||
| 
 | ||||
| 		/// <summary> | ||||
| 		/// 自定义设置用户属性 | ||||
| 		/// </summary> | ||||
| 		/// <param name="key"></param> | ||||
| 		/// <param name="value"></param> | ||||
| 		private static void CustomSetUserProperty(string key, string value) | ||||
| 		{ | ||||
| 			try | ||||
| 			{ | ||||
| 				GuruAnalytics.Instance.SetUserProperty(key, value); | ||||
| 				UpdateAllUserProperties(); // 同步所有的ID | ||||
| 			} | ||||
| 			catch (Exception ex) | ||||
| 			{ | ||||
| 				if (IsFirebaseReady) | ||||
| 				{ | ||||
| 					Crashlytics.LogException(ex); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					Debug.LogException(ex); | ||||
| 				} | ||||
| 			} | ||||
| 			 | ||||
| 		} | ||||
| 	     | ||||
| 		#region 设置太极02 值 | ||||
| 		 | ||||
| 	    /// <summary> | ||||
| 	    /// 设置太极02阀值 | ||||
| 	    /// </summary> | ||||
|  |  | |||
|  | @ -165,6 +165,8 @@ namespace Guru | |||
| 				// 填充相关的追踪事件 | ||||
| 				_guruEventDriver.AddProperty(key, value); | ||||
| 				_firebaseEventDriver.AddProperty(key, value); | ||||
| 				// 更新所有必要的用户属性 | ||||
| 				ApplyAllUserProperties(); | ||||
| 				Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{key}, propertyValue:{value}"); | ||||
| 			} | ||||
| 			catch (Exception ex) | ||||
|  |  | |||
|  | @ -221,13 +221,25 @@ namespace Guru | |||
| 		 | ||||
| 		public static string ADJUST_ID | ||||
| 		{ | ||||
| 			get => PlayerPrefs.GetString(nameof(ADJUST_ID), ""); | ||||
| 			get | ||||
| 			{ | ||||
| #if UNITY_EDITOR | ||||
| 				return "editor_fake_adjust_id"; | ||||
| #endif | ||||
| 				return PlayerPrefs.GetString(nameof(ADJUST_ID), ""); | ||||
| 			} | ||||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_ID), value); | ||||
| 		} | ||||
| 		 | ||||
| 
 | ||||
| 		public static string ADJUST_ADID | ||||
| 		{ | ||||
| 			get => PlayerPrefs.GetString(nameof(ADJUST_ADID), ""); | ||||
| 			get | ||||
| 			{ | ||||
| #if UNITY_IOS | ||||
| 				return "not_for_ios"; | ||||
| #endif | ||||
| 				return PlayerPrefs.GetString(nameof(ADJUST_ADID), ""); | ||||
| 			} | ||||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_ADID), value); | ||||
| 		} | ||||
| 
 | ||||
|  | @ -238,10 +250,16 @@ namespace Guru | |||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_IDFA), value); | ||||
| 		} | ||||
| 		 | ||||
| 		public static string ADJUST_GPSADID | ||||
| 		public static string ADJUST_IDFV | ||||
| 		{ | ||||
| 			get => PlayerPrefs.GetString(nameof(ADJUST_GPSADID), ""); | ||||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_GPSADID), value); | ||||
| 			get => PlayerPrefs.GetString(nameof(ADJUST_IDFV), ""); | ||||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_IDFV), value); | ||||
| 		} | ||||
| 		 | ||||
| 		public static string ADJUST_GOOGLE_ADID | ||||
| 		{ | ||||
| 			get => PlayerPrefs.GetString(nameof(ADJUST_GOOGLE_ADID), ""); | ||||
| 			set => PlayerPrefs.SetString(nameof(ADJUST_GOOGLE_ADID), value); | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -61,7 +61,7 @@ namespace Guru | |||
| 			firebaseAppInstanceId = IPMConfig.FIREBASE_ID; | ||||
| 			idfa = IPMConfig.ADJUST_IDFA; | ||||
| 			adid = IPMConfig.ADJUST_ADID; | ||||
| 			gpsAdid = IPMConfig.ADJUST_GPSADID; | ||||
| 			gpsAdid = IPMConfig.ADJUST_GOOGLE_ADID; | ||||
| 			userUuid = IPMConfig.IPM_UUID; | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue