fix: 修复启动时自打点没有上报用户属性的 BUG
							parent
							
								
									5b1097464d
								
							
						
					
					
						commit
						8d1afddcd5
					
				|  | @ -252,6 +252,20 @@ namespace Guru | |||
|             if (Model.IsNoAds) SetBuyNoAds(true); // 设置用户已经购买了去广告 | ||||
|         } | ||||
| 
 | ||||
|         private static HashSet<string> _userPropertyExistKeys = new HashSet<string>(50); | ||||
| 
 | ||||
|         private static void RecordUserPropertyKey(string key) | ||||
|         { | ||||
|             if(_userPropertyExistKeys == null) | ||||
|                 _userPropertyExistKeys = new HashSet<string>(50); | ||||
|              | ||||
|             if(!HasUserPropertyKey(key)) _userPropertyExistKeys.Add(key); | ||||
|         } | ||||
|          | ||||
|         private static bool HasUserPropertyKey(string key) | ||||
|         { | ||||
|             return _userPropertyExistKeys?.Contains(key) ?? false; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|  | @ -266,6 +280,7 @@ namespace Guru | |||
|                 UnityEngine.Debug.LogError($"{Tag} :: SetUserProperty {key}:{value} ::Please call <GuruSDK.Start()> first, before you call <SetUserProperty>."); | ||||
|                 return; | ||||
|             } | ||||
|             RecordUserPropertyKey(key); | ||||
|             Analytics.SetUserProperty(key, value); | ||||
|         } | ||||
| 
 | ||||
|  | @ -331,6 +346,62 @@ namespace Guru | |||
|             SetUserProperty(Analytics.PropertyIsIAPUser, isIapUser? "true" : "false"); | ||||
|         } | ||||
| 
 | ||||
|         public static void SetFirstOpenTime(string timestamp) | ||||
|         { | ||||
|             SetUserProperty(Analytics.PropertyFirstOpenTime, timestamp); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 初始化时调用一下所有的属性打点 | ||||
|         /// </summary> | ||||
|         private static void InitCallAllUserProperties() | ||||
|         { | ||||
|             if(!HasUserPropertyKey(Consts.PropertyFirstOpenTime))  | ||||
|                 SetFirstOpenTime(TimeUtil.GetCurrentTimeStamp().ToString());  | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyIsIAPUser))  | ||||
|                 SetUserIsIAP(Model?.IsIapUser ?? false); | ||||
| 
 | ||||
|             if (!HasUserPropertyKey(Consts.PropertyLevel)) | ||||
|                 SetUserBLevel(Model?.SuccessLevelId ?? 0); | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyUserID) && !string.IsNullOrEmpty(UID))  | ||||
|                 SetUserProperty(Consts.PropertyUserID, UID);  | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyDeviceID) && !string.IsNullOrEmpty(DeviceId))  | ||||
|                 SetUserProperty(Consts.PropertyDeviceID, DeviceId);  | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyIAPCoin))  | ||||
|                 SetUserPaidCoins(0);  | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyNonIAPCoin))  | ||||
|                 SetUserFreeCoins(0);  | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyCoin))  | ||||
|                 SetUserTotalCoins(0); | ||||
| 
 | ||||
|             if (!HasUserPropertyKey(Consts.PropertyGrade)) | ||||
|                 SetUserGrade(0); | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyExp)) | ||||
|                 SetUserExp(0); | ||||
|              | ||||
|             if(!HasUserPropertyKey(Consts.PropertyHp)) | ||||
|                 SetUserHp(0); | ||||
| 
 | ||||
| #if UNITY_IOS | ||||
|             if(!HasUserPropertyKey(Consts.PropertyATTStatus)) | ||||
|                 SetUserProperty(Consts.PropertyATTStatus, "notDetermined"); | ||||
| #endif | ||||
| 
 | ||||
|             if(!HasUserPropertyKey(Consts.PropertyNotiPerm)) | ||||
|                 SetUserProperty(Consts.PropertyNotiPerm, "not_determined"); | ||||
|              | ||||
|              | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region SDK 打点 | ||||
|  |  | |||
|  | @ -211,6 +211,7 @@ namespace Guru | |||
| 			public const string PropertyPicture = "picture"; // 玩家在主线的mapid | ||||
| 			public const string PropertyNoAds = "no_ads"; // 玩家是否去广告 | ||||
| 			public const string PropertyATTStatus = "att_status";  // ATT 状态 | ||||
| 			public const string PropertyNotiPerm = "noti_perm";  // Notification Permission 状态 | ||||
| 			public const string PropertyGDPR = "gdpr"; // GDPR状态 | ||||
| 			 | ||||
| 			// 经济相关 | ||||
|  |  | |||
|  | @ -114,7 +114,7 @@ namespace Guru | |||
|         { | ||||
|             _initTime = DateTime.Now.ToUniversalTime(); | ||||
|             // ----- First Open Time ----- | ||||
|             Analytics.SetUserProperty(Analytics.FirstOpenTime, GetFirstOpenTime()); | ||||
|             SetFirstOpenTime(GetFirstOpenTime());  // FirstOpenTime  | ||||
|             LogI($"#1 ---- Guru SDK [{Version}] ----\n{config.ToString()}"); | ||||
|             Instance.StartWithConfig(config, onComplete); | ||||
|         } | ||||
|  | @ -223,6 +223,9 @@ namespace Guru | |||
|             LogI($"#5 --- sync sdk time ---"); | ||||
|             var sp = DateTime.Now.ToUniversalTime() - _initTime; | ||||
|             LogSDKInitTime(sp.TotalSeconds); | ||||
|              | ||||
|             // 上报所有初始化用户属性 | ||||
|             InitCallAllUserProperties(); | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue