update: 重构用户属性上报逻辑, CodeReview
							parent
							
								
									cc65e9173c
								
							
						
					
					
						commit
						aec21f3789
					
				|  | @ -31,6 +31,7 @@ namespace Guru | ||||||
|         public int b_play = 0; |         public int b_play = 0; | ||||||
|         public int buy_count = 0; |         public int buy_count = 0; | ||||||
|         public bool no_ads = false; |         public bool no_ads = false; | ||||||
|  |         public string first_open_time = GetFirstOpenTime(); | ||||||
|          |          | ||||||
|         public List<PurchasedProduct> purchased; |         public List<PurchasedProduct> purchased; | ||||||
| 
 | 
 | ||||||
|  | @ -96,6 +97,8 @@ namespace Guru | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public string FirstOpenTime => first_open_time; | ||||||
|  | 
 | ||||||
|         public bool IsIapUser => PurchasedCount > 0; |         public bool IsIapUser => PurchasedCount > 0; | ||||||
|          |          | ||||||
|         public bool IsNoAds |         public bool IsNoAds | ||||||
|  | @ -120,8 +123,6 @@ namespace Guru | ||||||
|         public BindableProperty<string> Uid => _uid; |         public BindableProperty<string> Uid => _uid; | ||||||
| 
 | 
 | ||||||
|         #region 初始化 |         #region 初始化 | ||||||
| 
 |  | ||||||
|          |  | ||||||
|         public static GuruSDKModel Load() |         public static GuruSDKModel Load() | ||||||
|         { |         { | ||||||
|             GuruSDKModel model = null; |             GuruSDKModel model = null; | ||||||
|  | @ -145,6 +146,8 @@ namespace Guru | ||||||
|             return model; |             return model; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|  |         public static string GetFirstOpenTime() => TimeUtil.GetCurrentTimeStamp().ToString(); | ||||||
|  | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// 保存至数据 |         /// 保存至数据 | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |  | ||||||
|  | @ -185,7 +185,7 @@ namespace Guru | ||||||
|         { |         { | ||||||
|             _attType = InitConfig.UseCustomConsent ? ATTManager.GUIDE_TYPE_CUSTOM : ATTManager.GUIDE_TYPE_ADMOB; // 点位属性确定 |             _attType = InitConfig.UseCustomConsent ? ATTManager.GUIDE_TYPE_CUSTOM : ATTManager.GUIDE_TYPE_ADMOB; // 点位属性确定 | ||||||
|             _initialAttStatus = ATTManager.GetStatus(); |             _initialAttStatus = ATTManager.GetStatus(); | ||||||
|             SetUserProperty(Analytics.ParameterATTStatus, _initialAttStatus); // 上报一个初始的状态 |             SetATTStatus(_initialAttStatus); // 上报一个初始的状态 | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         /// <summary> |         /// <summary> | ||||||
|  | @ -202,14 +202,15 @@ namespace Guru | ||||||
|         private void ReportAttStatus(string status) |         private void ReportAttStatus(string status) | ||||||
|         { |         { | ||||||
|             LogI($"{Tag} --- Get Att status:{status}  att Type:{_attType}  recall:{_autoReCallAtt}"); |             LogI($"{Tag} --- Get Att status:{status}  att Type:{_attType}  recall:{_autoReCallAtt}"); | ||||||
|             SetUserProperty(Analytics.ParameterATTStatus, status); // 当前的状态 |             SetATTStatus(_initialAttStatus); // 上报一个初始的状态 | ||||||
|  |             // SetUserProperty(Analytics.ParameterATTStatus, status); // 当前的状态 | ||||||
|              |              | ||||||
|             if (!string.IsNullOrEmpty(status)  |             if (!string.IsNullOrEmpty(status)  | ||||||
|                 && status != _initialAttStatus  |                 && status != _initialAttStatus  | ||||||
|                 && status !=  ATTManager.ATT_STATUS_NOT_DETERMINED) |                 && status !=  ATTManager.ATT_STATUS_NOT_DETERMINED) | ||||||
|             { |             { | ||||||
|                 // 上报点位: |                 // 上报点位: | ||||||
|                 Analytics.AttResult(status, _attType); |                 SetATTStatus(_initialAttStatus); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             switch(status) |             switch(status) | ||||||
|  |  | ||||||
|  | @ -321,8 +321,8 @@ namespace Guru | ||||||
|          |          | ||||||
|         public static void SetUID(string uid) |         public static void SetUID(string uid) | ||||||
|         { |         { | ||||||
|             SetUserProperty(Consts.PropertyUserID, uid); |  | ||||||
|             Analytics.SetUid(uid); |             Analytics.SetUid(uid); | ||||||
|  |             SetUserProperty(Consts.PropertyUserID, uid); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static void SetUserBLevel(int blevel) |         public static void SetUserBLevel(int blevel) | ||||||
|  | @ -389,7 +389,8 @@ namespace Guru | ||||||
| 
 | 
 | ||||||
|         public static void SetUserIsIAP(bool isIapUser) |         public static void SetUserIsIAP(bool isIapUser) | ||||||
|         { |         { | ||||||
|             SetUserProperty(Consts.PropertyIsIAPUser, isIapUser? "true" : "false"); |             // SetUserProperty(Consts.PropertyIsIAPUser, isIapUser? "true" : "false"); | ||||||
|  |             Analytics.SetIsIapUser(isIapUser); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static void SetFirstOpenTime(string timestamp) |         public static void SetFirstOpenTime(string timestamp) | ||||||
|  | @ -399,12 +400,14 @@ namespace Guru | ||||||
|          |          | ||||||
|         public static void SetNotiPerm(string status) |         public static void SetNotiPerm(string status) | ||||||
|         { |         { | ||||||
|             SetUserProperty(Consts.PropertyNotiPerm, status); |             // SetUserProperty(Consts.PropertyNotiPerm, status); | ||||||
|  |             Analytics.SetNotiPerm(status); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         public static void SetATTStatus(string status) |         public static void SetATTStatus(string status) | ||||||
|         { |         { | ||||||
|             SetUserProperty(Consts.PropertyATTStatus, status); |             // SetUserProperty(Consts.PropertyATTStatus, status); | ||||||
|  |             Analytics.SetAttStatus(status); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static void SetAdjustId(string adjustId) |         public static void SetAdjustId(string adjustId) | ||||||
|  | @ -428,18 +431,18 @@ namespace Guru | ||||||
|             if (_hasUserPropertiesInitiallyUpdated) return; |             if (_hasUserPropertiesInitiallyUpdated) return; | ||||||
|             _hasUserPropertiesInitiallyUpdated = true; |             _hasUserPropertiesInitiallyUpdated = true; | ||||||
|              |              | ||||||
|             SetFirstOpenTime(TimeUtil.GetCurrentTimeStamp().ToString());    //  first_open_time  |             SetFirstOpenTime(Model?.FirstOpenTime ?? GuruSDKModel.GetFirstOpenTime());    //  first_open_time  | ||||||
|             SetUserIsIAP(Model?.IsIapUser ?? false);    // is_iap_user |             SetUserIsIAP(Model?.IsIapUser ?? false);    // is_iap_user | ||||||
|             SetUserBLevel(Model?.SuccessLevelId ?? 0);  // b_level |             SetUserBLevel(Model?.SuccessLevelId ?? 0);  // b_level | ||||||
|             SetUserBLevel(Model?.TotalPlayedCount ?? 0); // b_play |             SetUserBLevel(Model?.TotalPlayedCount ?? 0); // b_play | ||||||
|             SetUserProperty(Consts.PropertyDeviceID, DeviceId); // device_id |             SetUserProperty(Consts.PropertyDeviceID, DeviceId); // device_id | ||||||
|          |          | ||||||
|             SetUserIapCoin(0); // iap_coin |             // SetUserIapCoin(0); // iap_coin | ||||||
|             SetUserNonIapCoin(0); // non_iap_coin |             // SetUserNonIapCoin(0); // non_iap_coin | ||||||
|             SetUserCoin(0);// coin |             // SetUserCoin(0);// coin | ||||||
|             SetUserGrade(0); // grade |             // SetUserGrade(0); // grade | ||||||
|             SetUserExp(0); // exp |             // SetUserExp(0); // exp | ||||||
|             SetUserHp(0); // hp |             // SetUserHp(0); // hp | ||||||
|              |              | ||||||
|             if(!string.IsNullOrEmpty(UID)) |             if(!string.IsNullOrEmpty(UID)) | ||||||
|                 SetUID(UID); // user_id |                 SetUID(UID); // user_id | ||||||
|  | @ -451,7 +454,6 @@ namespace Guru | ||||||
|             SetNetworkStatus(); // NetworkStatus |             SetNetworkStatus(); // NetworkStatus | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         #endregion |         #endregion | ||||||
| 
 | 
 | ||||||
|         #region SDK 打点 |         #region SDK 打点 | ||||||
|  |  | ||||||
|  | @ -690,11 +690,8 @@ namespace Guru | ||||||
|          |          | ||||||
|         private void InitNetworkMonitor() |         private void InitNetworkMonitor() | ||||||
|         { |         { | ||||||
|             // SetUserProperty(Consts.PropertyNetwork, GetNetworkStatus()); |             _networkStatusMonitor = new NetworkStatusMonitor(Analytics.SetNetworkStatus,  | ||||||
|             _networkStatusMonitor = new NetworkStatusMonitor(status => |                 lastStatus => | ||||||
|             { |  | ||||||
|                 SetUserProperty(Consts.PropertyNetwork, status); |  | ||||||
|             }, lastStatus => |  | ||||||
|             { |             { | ||||||
|                 LogEvent("guru_offline", new Dictionary<string, dynamic>() |                 LogEvent("guru_offline", new Dictionary<string, dynamic>() | ||||||
|                 { |                 { | ||||||
|  | @ -727,18 +724,22 @@ namespace Guru | ||||||
| 
 | 
 | ||||||
|         private void OnGetGuruUID(bool success) |         private void OnGetGuruUID(bool success) | ||||||
|         { |         { | ||||||
|             Callbacks.SDK.InvokeOnGuruUserAuthResult(success); |  | ||||||
| 
 |  | ||||||
|             if (success) |             if (success) | ||||||
|             { |             { | ||||||
|  |                 Analytics.ShouldFlushGuruEvents(); | ||||||
|  |                  | ||||||
|                 Model.UserId = IPMConfig.IPM_UID; |                 Model.UserId = IPMConfig.IPM_UID; | ||||||
|                 if (GuruIAP.Instance != null) |                 if (GuruIAP.Instance != null) | ||||||
|                 { |                 { | ||||||
|                     GuruIAP.Instance.SetUID(UID); |                     GuruIAP.Instance.SetUID(UID); | ||||||
|                     GuruIAP.Instance.SetUUID(UUID); |                     GuruIAP.Instance.SetUUID(UUID); | ||||||
|                 } |                 } | ||||||
|  |                  | ||||||
|  |                 // 自打点设置用户 ID | ||||||
|                 SetUID(UID); |                 SetUID(UID); | ||||||
|             } |             } | ||||||
|  |              | ||||||
|  |             Callbacks.SDK.InvokeOnGuruUserAuthResult(success); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         private void OnGetFirebaseId(string fid) |         private void OnGetFirebaseId(string fid) | ||||||
|  | @ -788,37 +789,47 @@ namespace Guru | ||||||
|             string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? ""; |             string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? ""; | ||||||
|             string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId; |             string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId; | ||||||
| 
 | 
 | ||||||
|             if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID)) |             // if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID)) | ||||||
|                 ReportAdjustId(IPMConfig.ADJUST_ID); // 二次启动后,若有值则立即上报属性 |             //     Analytics.SetAdjustId(IPMConfig.ADJUST_ID); // 二次启动后,若有值则立即上报属性 | ||||||
| 					 | 					 | ||||||
|             AdjustService.StartService(appToken, fbAppId, firebaseId, DeviceId, |             AdjustService.StartService(appToken, fbAppId, firebaseId, DeviceId, | ||||||
|                 OnAdjustInitComplete, onDeeplinkCallback , googleAdid => IPMConfig.ADJUST_GOOGLE_ADID = googleAdid); |                 OnAdjustInitComplete, onDeeplinkCallback ,OnGetGoogleAdId ); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private static void OnAdjustInitComplete(string adjustId) |         /// <summary> | ||||||
|  |         /// Adjust 初始化结束 | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="adjustId"></param> | ||||||
|  |         /// <param name="idfv"></param> | ||||||
|  |         /// <param name="idfa"></param> | ||||||
|  |         private static void OnAdjustInitComplete(string adjustId, string idfv, string idfa) | ||||||
|         { |         { | ||||||
|  |             Debug.Log($"{Tag} --- OnAdjustInitComplete:  adjustId:{adjustId}  idfv:{idfv}  idfa:{idfa}"); | ||||||
|  |              | ||||||
|             // 获取 ADID  |             // 获取 ADID  | ||||||
|             if (string.IsNullOrEmpty(adjustId)) |             if (string.IsNullOrEmpty(adjustId)) adjustId = "not_set"; | ||||||
|             { |             if (string.IsNullOrEmpty(idfv)) idfv = "not_set"; | ||||||
|                 adjustId = "not_set"; |             if (string.IsNullOrEmpty(idfa)) idfa = "not_set"; | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 IPMConfig.ADJUST_ID = adjustId; |  | ||||||
|             } |  | ||||||
|             ReportAdjustId(adjustId); |  | ||||||
|              |              | ||||||
|             IPMConfig.ADJUST_IDFA = AdjustService.IDFA; |             IPMConfig.ADJUST_ID = adjustId; | ||||||
|             IPMConfig.ADJUST_IDFV = AdjustService.IDFV; |             // IPMConfig.ADJUST_IDFV = idfv; | ||||||
|  |             // IPMConfig.ADJUST_IDFA = idfa; | ||||||
|  |              | ||||||
|  |             Analytics.SetAdjustId(adjustId); | ||||||
|  |             Analytics.SetIDFV(idfv); | ||||||
|  |             Analytics.SetIDFA(idfa); | ||||||
|             Analytics.OnAdjustInitComplete(); |             Analytics.OnAdjustInitComplete(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 |         private static void OnGetGoogleAdId(string googleAdId) | ||||||
|         private static void ReportAdjustId(string adjustId) |  | ||||||
|         { |         { | ||||||
|             SetUserProperty("adjust_id", adjustId); |             Debug.Log($"{Tag} --- OnGetGoogleAdId: {googleAdId}"); | ||||||
|             Debug.Log($"[SDK] --- Firebase + Adjust ID: {adjustId}"); |             // IPMConfig.ADJUST_GOOGLE_ADID = googleAdId; | ||||||
|  |             Analytics.SetGoogleAdId(googleAdId); | ||||||
|         } |         } | ||||||
|  |          | ||||||
|  | 
 | ||||||
|  |         | ||||||
|         #endregion |         #endregion | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue