From 8d1afddcd595363f49673c9032fe0971528185d6 Mon Sep 17 00:00:00 2001 From: huyufei Date: Fri, 24 May 2024 16:45:33 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20=E4=BF=AE=E5=A4=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E8=87=AA=E6=89=93=E7=82=B9=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E7=94=A8=E6=88=B7=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Code/SDK/GuruSDK.Analytics.cs | 71 +++++++++++++++++++++++++++ Runtime/Code/SDK/GuruSDK.Const.cs | 1 + Runtime/Code/SDK/GuruSDK.cs | 5 +- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Runtime/Code/SDK/GuruSDK.Analytics.cs b/Runtime/Code/SDK/GuruSDK.Analytics.cs index 779e896..3be005a 100644 --- a/Runtime/Code/SDK/GuruSDK.Analytics.cs +++ b/Runtime/Code/SDK/GuruSDK.Analytics.cs @@ -252,6 +252,20 @@ namespace Guru if (Model.IsNoAds) SetBuyNoAds(true); // 设置用户已经购买了去广告 } + private static HashSet _userPropertyExistKeys = new HashSet(50); + + private static void RecordUserPropertyKey(string key) + { + if(_userPropertyExistKeys == null) + _userPropertyExistKeys = new HashSet(50); + + if(!HasUserPropertyKey(key)) _userPropertyExistKeys.Add(key); + } + + private static bool HasUserPropertyKey(string key) + { + return _userPropertyExistKeys?.Contains(key) ?? false; + } /// @@ -266,6 +280,7 @@ namespace Guru UnityEngine.Debug.LogError($"{Tag} :: SetUserProperty {key}:{value} ::Please call first, before you call ."); 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); + } + + /// + /// 初始化时调用一下所有的属性打点 + /// + 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 打点 diff --git a/Runtime/Code/SDK/GuruSDK.Const.cs b/Runtime/Code/SDK/GuruSDK.Const.cs index 77e9242..4d02956 100644 --- a/Runtime/Code/SDK/GuruSDK.Const.cs +++ b/Runtime/Code/SDK/GuruSDK.Const.cs @@ -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状态 // 经济相关 diff --git a/Runtime/Code/SDK/GuruSDK.cs b/Runtime/Code/SDK/GuruSDK.cs index f5fb4e6..0a2ec90 100644 --- a/Runtime/Code/SDK/GuruSDK.cs +++ b/Runtime/Code/SDK/GuruSDK.cs @@ -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(); } ///