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