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