Compare commits
8 Commits
5c1f73fc18
...
85c8058158
| Author | SHA1 | Date |
|---|---|---|
|
|
85c8058158 | |
|
|
6d5bc2c3a4 | |
|
|
edf6214cea | |
|
|
c88de190a1 | |
|
|
dc991efbf3 | |
|
|
515c875ee8 | |
|
|
2aad845378 | |
|
|
c3b77622d9 |
|
|
@ -72,7 +72,7 @@ namespace Guru
|
|||
for (int i = 0; i < _params.Count; i++)
|
||||
{
|
||||
// 上报实验AB属性
|
||||
GuruAnalytics.SetUserProperty(_params[i].id, _params[i].group);
|
||||
GuruAnalytics.Instance.SetUserProperty(_params[i].id, _params[i].group);
|
||||
#if UNITY_EDITOR
|
||||
Debug.Log($"[AB] --- Add AB Param <color=cyan>{_params[i].ToString()}</color>");
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Guru
|
|||
public const string K_IAP_PURCHASE = "iap_purchase"; // 固定点位事件
|
||||
public const string K_SUB_PURCHASE = "sub_purchase"; // 固定点位事件
|
||||
|
||||
private static Action<string> _onSessionSuccessCallback;
|
||||
private static Action<string> _onInitComplete;
|
||||
|
||||
|
||||
private static string _adId = "";
|
||||
|
|
@ -43,6 +43,9 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
private static bool _isReady = false;
|
||||
public static bool IsReady => _isReady;
|
||||
|
||||
#region 启动服务
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -50,7 +53,9 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="appToken"></param>
|
||||
/// <param name="fbAppId">MIR 追踪 AppID</param>
|
||||
public static void StartService(string appToken, string fbAppId = "", Action<string> onSessionSuccess = null)
|
||||
/// <param name="onInitComplete"></param>
|
||||
/// <param name="onDeeplinkCallback"></param>
|
||||
public static void StartService(string appToken, string fbAppId = "", Action<string> onInitComplete = null, Action<string> onDeeplinkCallback = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(appToken))
|
||||
{
|
||||
|
|
@ -58,7 +63,7 @@ namespace Guru
|
|||
return;
|
||||
}
|
||||
|
||||
_onSessionSuccessCallback = onSessionSuccess;
|
||||
_onInitComplete = onInitComplete;
|
||||
|
||||
InstallEvent(IPMConfig.FIREBASE_ID, IPMConfig.IPM_DEVICE_ID); // 注入启动参数
|
||||
|
||||
|
|
@ -66,10 +71,13 @@ namespace Guru
|
|||
AdjustConfig config = new AdjustConfig(appToken, environment);
|
||||
config.setLogLevel(GetAdjustLogLevel());
|
||||
config.setDelayStart(DelayTime);
|
||||
|
||||
config.setPreinstallTrackingEnabled(true); // Adjust Preinstall
|
||||
config.setSessionSuccessDelegate(OnSessionSuccessCallback); // SessionSuccess
|
||||
|
||||
if(onDeeplinkCallback != null)
|
||||
config.setDeferredDeeplinkDelegate(onDeeplinkCallback);
|
||||
|
||||
|
||||
#if UNITY_ANDROID
|
||||
if (!string.IsNullOrEmpty(fbAppId)) config.setFbAppId(fbAppId); // 注入 MIR ID
|
||||
#endif
|
||||
|
|
@ -79,7 +87,6 @@ namespace Guru
|
|||
config.setLogDelegate(log => LogI(LOG_TAG, log));
|
||||
config.setEventSuccessDelegate(OnEventSuccessCallback);
|
||||
config.setEventFailureDelegate(OnEventFailureCallback);
|
||||
|
||||
config.setSessionFailureDelegate(OnSessionFailureCallback);
|
||||
config.setAttributionChangedDelegate(OnAttributionChangedCallback);
|
||||
#endif
|
||||
|
|
@ -87,9 +94,6 @@ namespace Guru
|
|||
SetupInstance();
|
||||
Adjust.start(config);
|
||||
|
||||
// 缓存标准属性
|
||||
_adjustId = Adjust.getAdid(); // 获取AdjustID
|
||||
|
||||
// 异步加载AdId
|
||||
FetchGoogleAdId();
|
||||
|
||||
|
|
@ -161,6 +165,22 @@ namespace Guru
|
|||
|
||||
#region 事件回调函数
|
||||
|
||||
/// <summary>
|
||||
/// Session 启动后回调
|
||||
/// 回调中可以获取实际的 AdjustID
|
||||
/// </summary>
|
||||
/// <param name="sessionSuccessData"></param>
|
||||
private static void OnSessionSuccessCallback(AdjustSessionSuccess sessionSuccessData)
|
||||
{
|
||||
LogI(LOG_TAG,$"{LOG_TAG} --- Session tracked successfully!");
|
||||
|
||||
var adid = sessionSuccessData.Adid;
|
||||
_adjustId = adid;
|
||||
_isReady = true;
|
||||
_onInitComplete?.Invoke(adid);
|
||||
}
|
||||
|
||||
|
||||
private static void OnAttributionChangedCallback(AdjustAttribution attributionData)
|
||||
{
|
||||
LogI(LOG_TAG, "Attribution changed!");
|
||||
|
|
@ -278,14 +298,6 @@ namespace Guru
|
|||
LogI(LOG_TAG, "WillRetry: " + eventFailureData.WillRetry.ToString());
|
||||
}
|
||||
|
||||
private static void OnSessionSuccessCallback(AdjustSessionSuccess sessionSuccessData)
|
||||
{
|
||||
LogI(LOG_TAG,$"{LOG_TAG} --- Session tracked successfully!");
|
||||
|
||||
var adid = sessionSuccessData.Adid;
|
||||
_onSessionSuccessCallback?.Invoke(adid);
|
||||
}
|
||||
|
||||
private static void OnSessionFailureCallback(AdjustSessionFailure sessionFailureData)
|
||||
{
|
||||
LogI(LOG_TAG,"Session tracking failed!");
|
||||
|
|
@ -359,16 +371,16 @@ namespace Guru
|
|||
/// 广告收入上报 (Adjust 特有的接口)
|
||||
/// </summary>
|
||||
/// <param name="adInfo"></param>
|
||||
public static void TrackADRevenue(MaxSdkBase.AdInfo adInfo)
|
||||
public static void TrackADRevenue(AdImpressionData impressionData)
|
||||
{
|
||||
if (adInfo == null)
|
||||
if (impressionData == null)
|
||||
return;
|
||||
|
||||
var adRevenue = new AdjustAdRevenue(AdjustConfig.AdjustAdRevenueSourceAppLovinMAX);
|
||||
adRevenue.setRevenue(adInfo.Revenue, "USD");
|
||||
adRevenue.setAdRevenueNetwork(adInfo.NetworkName);
|
||||
adRevenue.setAdRevenueUnit(adInfo.AdUnitIdentifier);
|
||||
adRevenue.setAdRevenuePlacement(adInfo.Placement);
|
||||
adRevenue.setRevenue(impressionData.value, "USD");
|
||||
adRevenue.setAdRevenueNetwork(impressionData.ad_source);
|
||||
adRevenue.setAdRevenueUnit(impressionData.ad_unit_name);
|
||||
adRevenue.setAdRevenuePlacement(impressionData.ad_placement);
|
||||
Adjust.trackAdRevenue(adRevenue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,37 +14,60 @@ namespace Guru
|
|||
public class GuruAnalytics
|
||||
{
|
||||
// Plugin Version
|
||||
public const string Version = "1.10.5";
|
||||
public const string Version = "1.11.1";
|
||||
|
||||
public static readonly string Tag = "[ANU]";
|
||||
private static readonly string ActionName = "logger_error";
|
||||
internal const int EventPriorityDefault = 10;
|
||||
private const int EventPriorityDefault = 10;
|
||||
|
||||
private static IAnalyticsAgent _agent;
|
||||
|
||||
public static IAnalyticsAgent Agent
|
||||
private static GuruAnalytics _instance;
|
||||
public static GuruAnalytics Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
throw new Exception("GuruAnalytics not initialized. Please call <Analytics.InitAnalytics()> first.");
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool _isReady = false;
|
||||
public bool IsReady => _isReady;
|
||||
|
||||
private IAnalyticsAgent _agent;
|
||||
private IAnalyticsAgent Agent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_agent == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_agent = new AnalyticsAgentStub();
|
||||
_agent = new AnalyticsAgentMock();
|
||||
#elif UNITY_ANDROID
|
||||
_agent = new AnalyticsAgentAndroid();
|
||||
#elif UNITY_IOS
|
||||
_agent = new AnalyticsAgentIOS();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_agent == null)
|
||||
{
|
||||
throw new NotImplementedException("You Should Implement IAnalyticsAgent on platform first.");
|
||||
}
|
||||
|
||||
return _agent;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> _userProperties;
|
||||
private Dictionary<string, string> _userProperties;
|
||||
/// <summary>
|
||||
/// 用户属性缓存字典
|
||||
/// </summary>
|
||||
public static Dictionary<string, string> UserProperties
|
||||
private Dictionary<string, string> UserProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -59,15 +82,13 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 错误 code 表
|
||||
/// </summary>
|
||||
public static List<int> ErrorCodeList = new List<int>();
|
||||
|
||||
private static bool _autoSyncProperties = false;
|
||||
private static bool _enableErrorLog = false;
|
||||
public List<int> ErrorCodeList = new List<int>();
|
||||
private bool _enableErrorLog = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启动日志错误上报
|
||||
/// </summary>
|
||||
public static bool EnableErrorLog
|
||||
public bool EnableErrorLog
|
||||
{
|
||||
get => _enableErrorLog;
|
||||
set
|
||||
|
|
@ -83,37 +104,40 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 初始化接口
|
||||
/// </summary>
|
||||
public static void Init(string appId, string deviceInfo, bool isDebug = false,
|
||||
bool enableErrorLog = false, bool syncProperties = false)
|
||||
public static void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false,
|
||||
bool enableErrorLog = false)
|
||||
{
|
||||
Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialing...");
|
||||
|
||||
_autoSyncProperties = syncProperties;
|
||||
_enableErrorLog = enableErrorLog;
|
||||
Agent?.Init(appId, deviceInfo, isDebug);
|
||||
if(_enableErrorLog) InitCallbacks(); // 激活错误日志回调
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new GuruAnalytics();
|
||||
_instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug);
|
||||
_instance.EnableErrorLog = enableErrorLog;
|
||||
_instance._isReady = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置视图名称
|
||||
/// </summary>
|
||||
/// <param name="screenName"></param>
|
||||
public static void SetScreen(string screenName)
|
||||
public void SetScreen(string screenName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(screenName)) return;
|
||||
CacheUserProperty($"screen_name", screenName);
|
||||
Agent?.SetScreen(screenName);
|
||||
Agent.SetScreen(screenName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置广告ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public static void SetAdId(string id)
|
||||
public void SetAdId(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
CacheUserProperty($"ad_id", id);
|
||||
Agent?.SetAdId(id);
|
||||
Agent.SetAdId(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -121,59 +145,59 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void SetUserProperty(string key, string value)
|
||||
public void SetUserProperty(string key, string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
|
||||
CacheUserProperty(key, value); // 添加用户属性
|
||||
Agent?.SetUserProperty(key, value);
|
||||
Agent.SetUserProperty(key, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置Firebase ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public static void SetFirebaseId(string id)
|
||||
public void SetFirebaseId(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
CacheUserProperty($"firebase_id", id);
|
||||
Agent?.SetFirebaseId(id);
|
||||
Agent.SetFirebaseId(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Adjust ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public static void SetAdjustId(string id)
|
||||
public void SetAdjustId(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
CacheUserProperty($"adjust_id", id);
|
||||
Agent?.SetAdjustId(id);
|
||||
Agent.SetAdjustId(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置设备ID
|
||||
/// </summary>
|
||||
/// <param name="deviceId"></param>
|
||||
public static void SetDeviceId(string deviceId)
|
||||
public void SetDeviceId(string deviceId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(deviceId)) return;
|
||||
CacheUserProperty($"device_id", deviceId);
|
||||
Agent?.SetDeviceId(deviceId);
|
||||
Agent.SetDeviceId(deviceId);
|
||||
}
|
||||
|
||||
|
||||
public static void SetAndroidID(string androidId)
|
||||
public void SetAndroidID(string androidId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(androidId)) return;
|
||||
CacheUserProperty(Analytics.PropertyAndroidID, androidId);
|
||||
}
|
||||
|
||||
public static void SetIDFV(string idfv)
|
||||
public void SetIDFV(string idfv)
|
||||
{
|
||||
if (string.IsNullOrEmpty(idfv)) return;
|
||||
CacheUserProperty(Analytics.PropertyIDFV, idfv);
|
||||
}
|
||||
|
||||
public static void SetIDFA(string idfa)
|
||||
public void SetIDFA(string idfa)
|
||||
{
|
||||
if (string.IsNullOrEmpty(idfa)) return;
|
||||
CacheUserProperty(Analytics.PropertyIDFA, idfa);
|
||||
|
|
@ -184,17 +208,17 @@ namespace Guru
|
|||
/// 设置用户ID
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
public static void SetUid(string uid)
|
||||
public void SetUid(string uid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uid)) return;
|
||||
CacheUserProperty($"uid", uid);
|
||||
Agent?.SetUid(uid);
|
||||
Agent.SetUid(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报事件成功率
|
||||
/// </summary>
|
||||
public static void ReportEventSuccessRate() => Agent?.ReportEventSuccessRate();
|
||||
public void ReportEventSuccessRate() => Agent.ReportEventSuccessRate();
|
||||
|
||||
/// <summary>
|
||||
/// 上报打点事件
|
||||
|
|
@ -202,21 +226,19 @@ namespace Guru
|
|||
/// <param name="eventName">事件名称</param>
|
||||
/// <param name="data">INT类型的值</param>
|
||||
/// <param name="priority"></param>
|
||||
public static void LogEvent(string eventName, Dictionary<string, dynamic> data = null, int priority = -1)
|
||||
public void LogEvent(string eventName, Dictionary<string, dynamic> data = null, int priority = -1)
|
||||
{
|
||||
if(_autoSyncProperties)
|
||||
UpdateAllUserProperties(); // 每次打点更新用户属性
|
||||
|
||||
string raw = "";
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
raw = BuildParamsJson(data);
|
||||
}
|
||||
if (priority < 0) priority = EventPriorityDefault;
|
||||
Debug.Log($"{Tag} event:{eventName} | raw: {raw} | priority: {priority}");
|
||||
Agent?.LogEvent(eventName, raw, priority);
|
||||
Debug.Log($"{Tag} --- LogEvent GuruAnalytics:{eventName} | raw: {raw} | priority: {priority}");
|
||||
Agent.LogEvent(eventName, raw, priority);
|
||||
}
|
||||
|
||||
/*
|
||||
private static string BuildParamsString(Dictionary<string, dynamic> data)
|
||||
{
|
||||
string raw = "";
|
||||
|
|
@ -228,8 +250,9 @@ namespace Guru
|
|||
}
|
||||
return raw;
|
||||
}
|
||||
*/
|
||||
|
||||
private static string BuildParamsJson(Dictionary<string, dynamic> data)
|
||||
private string BuildParamsJson(Dictionary<string, dynamic> data)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -247,6 +270,7 @@ namespace Guru
|
|||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 构建带有类型格式的Str值
|
||||
/// </summary>
|
||||
|
|
@ -267,15 +291,16 @@ namespace Guru
|
|||
|
||||
return $"{kvp.Key}:s{kvp.Value}";
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 设置太极02值
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public static void SetTch02Value(double value)
|
||||
public void SetTch02Value(double value)
|
||||
{
|
||||
Debug.Log($"{Tag} set tch_02_value:{value}");
|
||||
Agent?.SetTch02Value(value);
|
||||
Agent.SetTch02Value(value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -296,37 +321,19 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
private static void CacheUserProperty(string key, string value)
|
||||
private void CacheUserProperty(string key, string value)
|
||||
{
|
||||
bool needUpdate = !UserProperties.ContainsKey(key) || UserProperties[key] != value;
|
||||
// bool needUpdate = !UserProperties.ContainsKey(key) || UserProperties[key] != value;
|
||||
UserProperties[key] = value;
|
||||
// if (needUpdate) UpdateAllUserProperties();
|
||||
}
|
||||
|
||||
|
||||
private static void UpdateAllUserProperties()
|
||||
{
|
||||
if (UserProperties != null && UserProperties.Count > 0)
|
||||
{
|
||||
var keys = UserProperties.Keys.ToArray();
|
||||
int i = 0;
|
||||
string key = "";
|
||||
while (i < keys.Length)
|
||||
{
|
||||
key = keys[i];
|
||||
if(!string.IsNullOrEmpty(key)) SetUserProperty(key, UserProperties[key]);
|
||||
i++;
|
||||
}
|
||||
keys = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 日志回调
|
||||
|
||||
private static void InitCallbacks()
|
||||
private void InitCallbacks()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -346,8 +353,8 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 获取SDK回调
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
private static void OnSDKCallback(string raw)
|
||||
/// <param name="raw"></param>
|
||||
private void OnSDKCallback(string raw)
|
||||
{
|
||||
if (string.IsNullOrEmpty(raw)) return;
|
||||
if (!raw.Contains($"\"{ActionName}\"")) return; // 不对其他行为的日志进行过滤
|
||||
|
|
@ -359,7 +366,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="errorInfo"></param>
|
||||
private static void OnLoggerErrorEvent(int code, string errorInfo = "")
|
||||
private void OnLoggerErrorEvent(int code, string errorInfo = "")
|
||||
{
|
||||
// Debug.Log($"{Tag} --- OnLoggerErrorEvent: code:{code}\tinfo:{errorInfo}");
|
||||
|
||||
|
|
@ -389,16 +396,12 @@ namespace Guru
|
|||
|
||||
Debug.Log($"{Tag} ------ ErrorLogInfo:: code:{codeString}\tinfo:{errorInfo}");
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
// Only for firebase GA
|
||||
Analytics.LogEvent("dev_audit", parameters,
|
||||
new Analytics.EventSetting() { EnableFirebaseAnalytics = true });
|
||||
#endif
|
||||
|
||||
Analytics.TrackEvent("dev_audit", parameters, new Analytics.EventSetting() { EnableFirebaseAnalytics = true });
|
||||
}
|
||||
|
||||
|
||||
private static bool ParseWithJson(string json)
|
||||
private bool ParseWithJson(string json)
|
||||
{
|
||||
Debug.Log($"{Tag} ------ ParseWithJson: json:\n{json}");
|
||||
|
||||
|
|
@ -435,7 +438,7 @@ namespace Guru
|
|||
{
|
||||
string p = "\"msg\":\"";
|
||||
string m = json;
|
||||
if (json.Contains(p)) m = json.Substring(json.IndexOf(p) + p.Length);
|
||||
if (json.Contains(p)) m = json.Substring(json.IndexOf(p, StringComparison.Ordinal) + p.Length);
|
||||
info = $"JsonEX:{m}";
|
||||
// Debug.Log($"{Tag} --- {info}");
|
||||
Analytics.LogCrashlytics(json, false);
|
||||
|
|
@ -445,22 +448,17 @@ namespace Guru
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void ParseWithRaw(string raw)
|
||||
/**
|
||||
private void ParseWithRaw(string raw)
|
||||
{
|
||||
int code = (int)AnalyticsCode.Unknown;
|
||||
string info = raw;
|
||||
var code = (int)AnalyticsCode.Unknown;
|
||||
string info;
|
||||
|
||||
//------- message send to unity ----------
|
||||
Debug.Log($"{Tag} get callback errorInfo:\n{raw}");
|
||||
|
||||
string patten = "";
|
||||
string patten2 = "";
|
||||
int idx = 0;
|
||||
int idx2 = 0;
|
||||
int len = 0;
|
||||
|
||||
|
||||
patten = "msg\":\"";
|
||||
var patten = "msg\":\"";
|
||||
if (raw.Contains(patten))
|
||||
{
|
||||
|
||||
|
|
@ -483,16 +481,16 @@ namespace Guru
|
|||
try
|
||||
{
|
||||
|
||||
idx = raw.IndexOf(patten, StringComparison.Ordinal) + patten.Length;
|
||||
var idx = raw.IndexOf(patten, StringComparison.Ordinal) + patten.Length;
|
||||
string act = raw.Substring(idx, ActionName.Length);
|
||||
if (act == ActionName)
|
||||
{
|
||||
patten = "code\":";
|
||||
patten2 = ",\"msg";
|
||||
idx = raw.IndexOf(patten);
|
||||
idx2 = raw.IndexOf(patten2);
|
||||
var patten2 = ",\"msg";
|
||||
idx = raw.IndexOf(patten, StringComparison.Ordinal);
|
||||
var idx2 = raw.IndexOf(patten2, StringComparison.Ordinal);
|
||||
|
||||
len = idx2 - (idx + patten.Length);
|
||||
var len = idx2 - (idx + patten.Length);
|
||||
if (len > 0)
|
||||
{
|
||||
string c = raw.Substring(idx + patten.Length, len);
|
||||
|
|
@ -531,12 +529,12 @@ namespace Guru
|
|||
{
|
||||
Analytics.LogCrashlytics(raw, false);
|
||||
Analytics.LogCrashlytics($"{Tag} --- format error:{raw}");
|
||||
OnLoggerErrorEvent(code, raw.Substring(raw.IndexOf("msg\":" ) + 5));
|
||||
OnLoggerErrorEvent(code, raw.Substring(raw.IndexOf("msg\":", StringComparison.Ordinal) + 5));
|
||||
}
|
||||
}
|
||||
**/
|
||||
|
||||
|
||||
private static void ReportCodeInfo(int code, string info)
|
||||
private void ReportCodeInfo(int code, string info)
|
||||
{
|
||||
var ac = (AnalyticsCode)code;
|
||||
Debug.Log($"{Tag} ------ Get Code And Info: code:{code}[{ac}] \tinfo:{info}");
|
||||
|
|
@ -592,7 +590,7 @@ namespace Guru
|
|||
|
||||
public static void TestOnCallback(string msg)
|
||||
{
|
||||
OnSDKCallback(msg);
|
||||
Instance.OnSDKCallback(msg);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// 自打点代理接口
|
||||
/// </summary>
|
||||
public interface IAnalyticsAgent
|
||||
{
|
||||
void Init(string appId, string deviceInfo, bool isDebug = false);
|
||||
void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false);
|
||||
void SetScreen(string screenName);
|
||||
void SetAdId(string id);
|
||||
void SetUserProperty(string key, string value);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
|
@ -76,12 +78,16 @@ namespace Guru
|
|||
|
||||
#region 接口实现
|
||||
|
||||
public void Init(string appId, string deviceInfo, bool isDebug = false)
|
||||
public async void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
||||
{
|
||||
_isDebug = isDebug;
|
||||
string bundleId = Application.identifier;
|
||||
// public static void init(String appId, String deviceInfo, String bundleId, boolean isDebug, boolean useWorker, boolean useCronet, String baseUrl)
|
||||
|
||||
// TODO: 将来把 CallStatic 转为异步实现
|
||||
CallStatic("init", appId, deviceInfo, bundleId, isDebug, UseWorker, UseCronet, BaseUrl); // 调用接口
|
||||
|
||||
onInitComplete?.Invoke();
|
||||
}
|
||||
|
||||
public void SetScreen(string screenName)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class AnalyticsAgentIOS: IAnalyticsAgent
|
||||
{
|
||||
|
||||
|
|
@ -55,13 +57,14 @@ namespace Guru
|
|||
}
|
||||
|
||||
|
||||
public void Init(string appId, string deviceInfo, bool isDebug = false)
|
||||
public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
||||
{
|
||||
_isDebug = isDebug;
|
||||
#if UNITY_IOS
|
||||
unityInitAnalytics(appId, deviceInfo, isDebug);
|
||||
unityInitException(); // 初始化报错守护进程
|
||||
#endif
|
||||
onInitComplete?.Invoke();
|
||||
}
|
||||
|
||||
public void SetScreen(string screenName)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
public class AnalyticsAgentStub: IAnalyticsAgent
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AnalyticsAgentMock: IAnalyticsAgent
|
||||
{
|
||||
|
||||
public static readonly string TAG = "[EDT]";
|
||||
|
|
@ -24,7 +27,7 @@ namespace Guru
|
|||
|
||||
}
|
||||
|
||||
public void Init(string appId, string deviceInfo, bool isDebug = false)
|
||||
public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_isShowLog = true;
|
||||
|
|
@ -32,6 +35,8 @@ namespace Guru
|
|||
_isDebug = isDebug;
|
||||
if(_isShowLog)
|
||||
Debug.Log($"{TAG} init with Debug: <color=orange>{isDebug}</color> appId:{appId} deviceInfo:{deviceInfo}");
|
||||
|
||||
onInitComplete?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -127,7 +132,7 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
Debug.Log($"{TAG} LogEvent: event:<color=orange>{eventName} ({priority})</color> Properties:\n{sb.ToString()}");
|
||||
Debug.Log($"{TAG} LogEvent: GuruAnalytics:<color=orange>{eventName} ({priority})</color> Properties:\n{sb.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ using UnityEngine.UI;
|
|||
|
||||
namespace Guru
|
||||
{
|
||||
public class CuruAnalyticsDemo: MonoBehaviour
|
||||
public class GuruAnalyticsDemo: MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool _isDebug = true;
|
||||
[SerializeField] private Button _btnInitSDK;
|
||||
|
|
@ -54,17 +54,22 @@ namespace Guru
|
|||
private void OnClickInit()
|
||||
{
|
||||
Debug.Log($"---- [DEMO] Call Analytics init");
|
||||
GuruAnalytics.Init(AppID, DeviceInfo, _isDebug);
|
||||
GuruAnalytics.Init(AppID, DeviceInfo, OnGuruAnalyticsInitComplete, _isDebug);
|
||||
}
|
||||
|
||||
private void OnGuruAnalyticsInitComplete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnClickStatus()
|
||||
{
|
||||
Debug.Log($"---- [DEMO] Report Stats IDs: UID:{UID} DeviceID:{DeviceID} FirebaseID:{FirebaseID} AdID:{AdID} AdjustID:{AdjustID}");
|
||||
GuruAnalytics.SetUid(UID);
|
||||
GuruAnalytics.SetDeviceId(DeviceID);
|
||||
GuruAnalytics.SetFirebaseId(FirebaseID);
|
||||
GuruAnalytics.SetAdId(AdID);
|
||||
GuruAnalytics.SetAdjustId(AdjustID);
|
||||
GuruAnalytics.Instance.SetUid(UID);
|
||||
GuruAnalytics.Instance.SetDeviceId(DeviceID);
|
||||
GuruAnalytics.Instance.SetFirebaseId(FirebaseID);
|
||||
GuruAnalytics.Instance.SetAdId(AdID);
|
||||
GuruAnalytics.Instance.SetAdjustId(AdjustID);
|
||||
}
|
||||
|
||||
private void OnClickUserProperties()
|
||||
|
|
@ -72,14 +77,14 @@ namespace Guru
|
|||
string item_category = "main";
|
||||
int level = 7;
|
||||
Debug.Log($"---- [DEMO] Call SetUserProperty: item_category:{item_category} level:{level}");
|
||||
GuruAnalytics.SetUserProperty("item_category", item_category);
|
||||
GuruAnalytics.SetUserProperty("level", level.ToString());
|
||||
GuruAnalytics.Instance.SetUserProperty("item_category", item_category);
|
||||
GuruAnalytics.Instance.SetUserProperty("level", level.ToString());
|
||||
}
|
||||
|
||||
private void OnClickEvents()
|
||||
{
|
||||
Debug.Log($"---- [DEMO] Report Screen: {ScreenName}");
|
||||
GuruAnalytics.SetScreen(ScreenName);
|
||||
GuruAnalytics.Instance.SetScreen(ScreenName);
|
||||
|
||||
string eventName = "user_get_coin";
|
||||
Dictionary<string, dynamic> data = new Dictionary<string, dynamic>()
|
||||
|
|
@ -99,19 +104,19 @@ namespace Guru
|
|||
Debug.Log(s);
|
||||
|
||||
Debug.Log($"---- [DEMO] Call LogEvent");
|
||||
GuruAnalytics.LogEvent(eventName, data);
|
||||
GuruAnalytics.Instance.LogEvent(eventName, data);
|
||||
}
|
||||
|
||||
private void OnClickEvents2()
|
||||
{
|
||||
string eventName = "user_data_loaded";
|
||||
GuruAnalytics.LogEvent(eventName);
|
||||
GuruAnalytics.Instance.LogEvent(eventName);
|
||||
}
|
||||
|
||||
|
||||
private void OnClickReport()
|
||||
{
|
||||
GuruAnalytics.ReportEventSuccessRate();
|
||||
GuruAnalytics.Instance.ReportEventSuccessRate();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ namespace Guru
|
|||
DmaResult = result;
|
||||
|
||||
//----------- Guru Analytics report ---------------
|
||||
Analytics.LogEvent("dma_gg", new Dictionary<string, dynamic>()
|
||||
Analytics.TrackEvent("dma_gg", new Dictionary<string, dynamic>()
|
||||
{
|
||||
{ "purpose", purposeStr },
|
||||
{ "result", result }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using UnityEngine;
|
||||
|
|
@ -30,6 +32,21 @@ namespace Guru
|
|||
Debug.Log($"{Tag} Consent Request -> deviceid: {deviceId} debugGeography: {debugGeography}");
|
||||
|
||||
#if UNITY_EDITOR
|
||||
SendEditorCallback();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 延迟触发 Consent
|
||||
/// </summary>
|
||||
private async void SendEditorCallback()
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
|
||||
string msg = callbackMsgFmt.Replace("$0", $"{DebugStatusCode}").Replace("$1",DebugMessage);
|
||||
var go = GameObject.Find(_objName);
|
||||
if (go != null)
|
||||
|
|
@ -40,9 +57,10 @@ namespace Guru
|
|||
{
|
||||
Debug.LogError($"{Tag} Can't find callback object");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取 DMA 字段
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
|
@ -18,7 +20,7 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
protected static readonly string Tag = "[Ads]";
|
||||
protected static readonly string Tag = "[SDK][ADS]";
|
||||
public bool IsInitialized => MaxSdk.IsInitialized() || _isServiceStarted;
|
||||
protected bool IsNetworkEnabled => Application.internetReachability != NetworkReachability.NotReachable;
|
||||
|
||||
|
|
@ -41,6 +43,9 @@ namespace Guru
|
|||
public static Action OnRewardFailed;
|
||||
public static Action OnRewardClosed;
|
||||
|
||||
private Dictionary<string, string> _reviewCreativeIds = new Dictionary<string, string>(10); // Creative ID 缓存: Cid : RCid
|
||||
private Dictionary<string, AdImpressionData> _impressionCache = new Dictionary<string, AdImpressionData>(10);
|
||||
|
||||
protected AdsModel _model;
|
||||
protected AdsInitSpec _initSpec = null;
|
||||
|
||||
|
|
@ -89,10 +94,12 @@ namespace Guru
|
|||
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
|
||||
MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnBannerRevenuePaidEvent;
|
||||
MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
|
||||
|
||||
//--------------- Banner 回调 -----------------
|
||||
MaxSdkCallbacks.Banner.OnAdLoadedEvent += OnBannerLoadedEvent;
|
||||
MaxSdkCallbacks.Banner.OnAdLoadFailedEvent += OnBannerFailedEvent;
|
||||
MaxSdkCallbacks.Banner.OnAdClickedEvent += OnBannerClickedEvent;
|
||||
MaxSdkCallbacks.Banner.OnAdReviewCreativeIdGeneratedEvent += OnAdReviewCreativeIdGeneratedEvent;
|
||||
//--------------- IV 回调 -----------------
|
||||
MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
|
||||
MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialFailedEvent;
|
||||
|
|
@ -100,6 +107,7 @@ namespace Guru
|
|||
MaxSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickEvent;
|
||||
MaxSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayEvent;
|
||||
MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialDismissedEvent;
|
||||
MaxSdkCallbacks.Interstitial.OnAdReviewCreativeIdGeneratedEvent += OnAdReviewCreativeIdGeneratedEvent;
|
||||
//--------------- RV 回调 -----------------
|
||||
MaxSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent;
|
||||
MaxSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdFailedEvent;
|
||||
|
|
@ -108,6 +116,11 @@ namespace Guru
|
|||
MaxSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent;
|
||||
MaxSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdDismissedEvent;
|
||||
MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent;
|
||||
MaxSdkCallbacks.Rewarded.OnAdReviewCreativeIdGeneratedEvent += OnAdReviewCreativeIdGeneratedEvent;
|
||||
|
||||
//--------------- Creative 回调 -----------------
|
||||
|
||||
|
||||
|
||||
//-------------- SDK 初始化 -------------------
|
||||
MaxSdk.SetExtraParameter("enable_black_screen_fixes", "true"); // 修复黑屏
|
||||
|
|
@ -174,7 +187,7 @@ namespace Guru
|
|||
|
||||
#endregion
|
||||
|
||||
#region ILRD
|
||||
#region 收益打点
|
||||
|
||||
private double TchAD001RevValue
|
||||
{
|
||||
|
|
@ -188,24 +201,45 @@ namespace Guru
|
|||
set => _model.TchAD02RevValue = value;
|
||||
}
|
||||
|
||||
public void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
||||
/// <summary>
|
||||
/// 上报广告收益
|
||||
/// </summary>
|
||||
/// <param name="adInfo"></param>
|
||||
/// <param name="reviewedCreativeId"></param>
|
||||
private void ReportAdsRevenue(AdImpressionData impressionData)
|
||||
{
|
||||
if (adInfo == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
Log.I( $"[ADRevenue] - adUnitId:{adUnitId}, Revenue:{adInfo?.Revenue : 0}");
|
||||
|
||||
// #1 ad_impression
|
||||
OnAdImpression(adInfo);
|
||||
Analytics.ADImpression(impressionData);
|
||||
|
||||
// #2 tch_001
|
||||
double revenue = adInfo.Revenue;
|
||||
double revenue = impressionData.value;
|
||||
CalcTaichi001Value(revenue);
|
||||
CalcTaichi02Value(revenue);
|
||||
|
||||
// #3 adjust_ad_revenue
|
||||
AdjustService.TrackADRevenue(adInfo);
|
||||
AdjustService.TrackADRevenue(impressionData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
||||
{
|
||||
if (adInfo == null) return;
|
||||
Debug.Log( $"{Tag} --- [Revenue] > [{adInfo.AdFormat}] --- adUnitId:{adUnitId}: UnitID:{adInfo.AdUnitIdentifier} Revenue:{adInfo.Revenue} CreativeId:{adInfo.CreativeIdentifier}");
|
||||
|
||||
try
|
||||
{
|
||||
if (_reviewCreativeIds.TryGetValue(adInfo.CreativeIdentifier, out var reviewCreativeId))
|
||||
{
|
||||
// 找到 RCid 的话则直接上报广告收益
|
||||
TryReportImpression(adInfo, reviewCreativeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 找不到的话会缓存 adInfo, 等待获取 RCid
|
||||
_impressionCache[adInfo.CreativeIdentifier] = CreateImpressionData(adInfo, "", Analytics.AdMAX);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -216,13 +250,30 @@ namespace Guru
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 广告ARO收益打点
|
||||
/// 构建 Impression 数据
|
||||
/// </summary>
|
||||
/// <param name="adInfo"></param>
|
||||
/// <param name="reviewCreativeId"></param>
|
||||
/// <param name="platform"></param>
|
||||
private void OnAdImpression(MaxSdkBase.AdInfo adInfo, string platform = "")
|
||||
/// <returns></returns>
|
||||
private AdImpressionData CreateImpressionData(MaxSdkBase.AdInfo adInfo, string reviewCreativeId = "", string platform = "")
|
||||
{
|
||||
Analytics.ADImpression(adInfo, platform);
|
||||
if (string.IsNullOrEmpty(platform)) platform = Analytics.AdMAX;
|
||||
|
||||
var impression = new AdImpressionData()
|
||||
{
|
||||
value = adInfo.Revenue,
|
||||
currency = Analytics.USD,
|
||||
ad_platform = platform,
|
||||
ad_format = adInfo.AdFormat,
|
||||
ad_unit_name = adInfo.AdUnitIdentifier,
|
||||
ad_source = adInfo.NetworkName,
|
||||
ad_placement = adInfo.NetworkPlacement,
|
||||
ad_creative_id = adInfo.CreativeIdentifier,
|
||||
review_creative_id = reviewCreativeId
|
||||
};
|
||||
|
||||
return impression;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -386,6 +437,7 @@ namespace Guru
|
|||
// --- fixed by Yufei 2024-5-29 为 don't report bads_loaded any more. ---
|
||||
// Analytics.ADBadsLoaded(AdParams.Build(adUnitId, adInfo,
|
||||
// duration: GetAdsLoadDuration(ref _badsloadStartTime), category: _badsCategory));
|
||||
Debug.Log( $"[SDK][Ads][Loaded] --- adUnitId:{adUnitId} Revenue:{adInfo.Revenue} Type:{adInfo.AdFormat} CreativeId:{adInfo.CreativeIdentifier}");
|
||||
OnBadsLoaded();
|
||||
}
|
||||
|
||||
|
|
@ -509,6 +561,8 @@ namespace Guru
|
|||
duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory));
|
||||
_interstitialRetryAttempt = 0;
|
||||
|
||||
Debug.Log( $"[SDK][Ads][Loaded] --- adUnitId:{adUnitId} Revenue:{adInfo.Revenue} Type:{adInfo.AdFormat} CreativeId:{adInfo.CreativeIdentifier}");
|
||||
|
||||
OnInterstitialLoaded?.Invoke();
|
||||
}
|
||||
|
||||
|
|
@ -661,6 +715,8 @@ namespace Guru
|
|||
duration: GetAdsLoadDuration(ref _radsLoadStartTime), category: _iadsCategory));
|
||||
_rewardRetryAttempt = 0;
|
||||
|
||||
Debug.Log( $"[SDK][Ads][Loaded] --- adUnitId:{adUnitId} Revenue:{adInfo.Revenue} Type:{adInfo.AdFormat} CreativeId:{adInfo.CreativeIdentifier}");
|
||||
|
||||
OnRewardLoaded?.Invoke();
|
||||
}
|
||||
|
||||
|
|
@ -782,5 +838,78 @@ namespace Guru
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreativeID
|
||||
|
||||
/// <summary>
|
||||
/// 获取 AdReviewCreativeId
|
||||
/// </summary>
|
||||
/// <param name="adUnitId"></param>
|
||||
/// <param name="reviewCreativeId"></param>
|
||||
/// <param name="adInfo"></param>
|
||||
private void OnAdReviewCreativeIdGeneratedEvent(string adUnitId, string reviewCreativeId, MaxSdkBase.AdInfo adInfo)
|
||||
{
|
||||
Debug.Log($"{Tag} --- ReviewCreativeId:{reviewCreativeId} adUnitId: {adUnitId} Type:{adInfo?.AdFormat ?? "NULL"} CreativeId: {adInfo?.CreativeIdentifier ?? "NULL"} Revenue:{adInfo.Revenue}");
|
||||
if (adInfo == null || string.IsNullOrEmpty(adInfo.CreativeIdentifier))
|
||||
{
|
||||
Debug.LogError($"{Tag} --- Get ReviewCreativeId:{reviewCreativeId} but CreativeIdentifier is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_reviewCreativeIds == null) _reviewCreativeIds = new Dictionary<string, string>(10);
|
||||
|
||||
|
||||
// 尝试直接上报广告收益 (可能存在异步上报的情况)
|
||||
if (!TryReportImpression(adInfo, reviewCreativeId))
|
||||
{
|
||||
_reviewCreativeIds[adInfo.CreativeIdentifier] = reviewCreativeId; // 如果上报未成功, 则缓存reviewCreativeId
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试上报数据
|
||||
/// </summary>
|
||||
/// <param name="adInfo"></param>
|
||||
/// <param name="reviewCreativeId"></param>
|
||||
/// <returns></returns>
|
||||
private bool TryReportImpression(MaxSdk.AdInfo adInfo, string reviewCreativeId = "")
|
||||
{
|
||||
string creativeId = adInfo.CreativeIdentifier;
|
||||
bool result = false;
|
||||
List<string> removeList = new List<string>();
|
||||
|
||||
if (_impressionCache.TryGetValue(creativeId, out var impressionData))
|
||||
{
|
||||
if(string.IsNullOrEmpty(impressionData.review_creative_id))
|
||||
impressionData.review_creative_id = reviewCreativeId;
|
||||
|
||||
ReportAdsRevenue(impressionData);
|
||||
removeList.Add(creativeId);
|
||||
result = true;
|
||||
}
|
||||
|
||||
// 清理超过 3 秒未上报的数据
|
||||
foreach (var imp in _impressionCache.Values)
|
||||
{
|
||||
if (imp.GetPassedSecond() > 3.0)
|
||||
{
|
||||
ReportAdsRevenue(imp);
|
||||
removeList.Add(imp.ad_creative_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (removeList.Count > 0)
|
||||
{
|
||||
foreach (var k in removeList)
|
||||
{
|
||||
_impressionCache.Remove(k);
|
||||
_reviewCreativeIds.Remove(k);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// AdImpression 对象
|
||||
/// </summary>
|
||||
public class AdImpressionData
|
||||
{
|
||||
public double value;
|
||||
public string currency = "USD";
|
||||
public string ad_platform = "MAX";
|
||||
public string ad_source;
|
||||
public string ad_format;
|
||||
public string ad_unit_name;
|
||||
public string ad_placement;
|
||||
public string ad_creative_id;
|
||||
public string review_creative_id;
|
||||
|
||||
public DateTime createTime;
|
||||
|
||||
public AdImpressionData()
|
||||
{
|
||||
createTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取自创建开始经过的秒数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetPassedSecond()
|
||||
{
|
||||
return (DateTime.UtcNow - createTime).TotalSeconds;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1aca2a4507b94dfe9f88040125708edb
|
||||
timeCreated: 1721883318
|
||||
|
|
@ -22,7 +22,7 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
private static AdjustEvent CreateAdjustEvent(string eventName)
|
||||
internal static AdjustEvent CreateAdjustEvent(string eventName)
|
||||
{
|
||||
string tokenID = GetAdjustEventToken(eventName);
|
||||
if (string.IsNullOrEmpty(tokenID))
|
||||
|
|
|
|||
|
|
@ -59,26 +59,26 @@ namespace Guru
|
|||
//---------------------- BANNER -------------------------
|
||||
public static void ADBadsLoad(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventBadsLoad, BuildAdEventData(adParams));
|
||||
TrackEvent(EventBadsLoad, BuildAdEventData(adParams));
|
||||
}
|
||||
public static void ADBadsLoaded(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventBadsLoaded, BuildAdEventData(adParams));
|
||||
TrackEvent(EventBadsLoaded, BuildAdEventData(adParams));
|
||||
}
|
||||
public static void ADBadsFailed(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventBadsFailed, BuildAdEventData(adParams));
|
||||
TrackEvent(EventBadsFailed, BuildAdEventData(adParams));
|
||||
}
|
||||
/// <summary>
|
||||
/// 广告点击
|
||||
/// </summary>
|
||||
public static void ADBadsClick(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventBadsClick, BuildAdEventData(adParams));
|
||||
TrackEvent(EventBadsClick, BuildAdEventData(adParams));
|
||||
}
|
||||
public static void ADBadsImp(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventBadsImp, BuildAdEventData(adParams));
|
||||
TrackEvent(EventBadsImp, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
public static void ADBadsHide( int loadedTimes, int failTimes)
|
||||
|
|
@ -88,7 +88,7 @@ namespace Guru
|
|||
["loaded_times"] = loadedTimes,
|
||||
["fail_times"] = failTimes
|
||||
};
|
||||
LogEvent(EventBadsHide, dict);
|
||||
TrackEvent(EventBadsHide, dict);
|
||||
}
|
||||
//---------------------- INTERSTITIAL -------------------------
|
||||
/// <summary>
|
||||
|
|
@ -96,7 +96,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsLoad(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsLoad, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsLoad, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -104,7 +104,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsLoaded(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsLoaded, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsLoaded, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -112,7 +112,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsFailed(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsFailed, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsFailed, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -120,7 +120,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsImp(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsImp, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsImp, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -128,7 +128,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsClick(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsClick, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsClick, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -136,7 +136,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADIadsClose(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventIadsClose, BuildAdEventData(adParams));
|
||||
TrackEvent(EventIadsClose, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
//---------------------- REWARDS -------------------------
|
||||
|
|
@ -145,28 +145,28 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADRadsLoad(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsLoad, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsLoad, BuildAdEventData(adParams));
|
||||
}
|
||||
/// <summary>
|
||||
/// 广告拉取成功
|
||||
/// </summary>
|
||||
public static void ADRadsLoaded(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsLoaded, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsLoaded, BuildAdEventData(adParams));
|
||||
}
|
||||
/// <summary>
|
||||
/// 广告拉取失败
|
||||
/// </summary>
|
||||
public static void ADRadsFailed(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsFailed, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsFailed, BuildAdEventData(adParams));
|
||||
}
|
||||
/// <summary>
|
||||
/// 广告展示
|
||||
/// </summary>
|
||||
public static void ADRadsImp(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsImp, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsImp, BuildAdEventData(adParams));
|
||||
}
|
||||
/// <summary>
|
||||
/// 广告完成观看发奖励
|
||||
|
|
@ -174,7 +174,7 @@ namespace Guru
|
|||
public static void ADRadsRewarded(AdParams adParams)
|
||||
{
|
||||
var data = BuildAdEventData(adParams);
|
||||
LogEvent(EventRadsRewarded, data);
|
||||
TrackEvent(EventRadsRewarded, data);
|
||||
|
||||
if (RadsRewardCount == 0)
|
||||
{
|
||||
|
|
@ -195,7 +195,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADRadsFirstRewarded(Dictionary<string, object> data)
|
||||
{
|
||||
LogEvent(EventFirstRadsRewarded, data);
|
||||
TrackEvent(EventFirstRadsRewarded, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -203,7 +203,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADRadsClick(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsClick, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsClick, BuildAdEventData(adParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -211,7 +211,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
public static void ADRadsClose(AdParams adParams)
|
||||
{
|
||||
LogEvent(EventRadsClose, BuildAdEventData(adParams));
|
||||
TrackEvent(EventRadsClose, BuildAdEventData(adParams));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Guru
|
|||
public static readonly string USD = "USD";
|
||||
// 广告平台
|
||||
public static readonly string AdMAX = "MAX";
|
||||
public static readonly string AdIronSource = "IronSource";
|
||||
|
||||
//IAP打点事件
|
||||
public static readonly string EventIAPFirst = "first_iap";
|
||||
|
|
@ -42,6 +43,7 @@ namespace Guru
|
|||
public static readonly string EventIadsFailed = "iads_failed";
|
||||
public static readonly string EventIadsImp = "iads_imp";
|
||||
public static readonly string EventIadsClick = "iads_clk";
|
||||
public static readonly string EventIadsPaid = "iads_paid";
|
||||
public static readonly string EventIadsClose = "iads_close";
|
||||
|
||||
//激励视频广告打点事件
|
||||
|
|
@ -51,6 +53,7 @@ namespace Guru
|
|||
public static readonly string EventRadsImp = "rads_imp";
|
||||
public static readonly string EventRadsRewarded = "rads_rewarded";
|
||||
public static readonly string EventRadsClick = "rads_clk";
|
||||
public static readonly string EventRadsPaid = "rads_paid";
|
||||
public static readonly string EventRadsClose = "rads_close";
|
||||
public static readonly string EventFirstRadsRewarded = "first_rads_rewarded";
|
||||
|
||||
|
|
@ -78,7 +81,10 @@ namespace Guru
|
|||
public static readonly string ParameterReplay = "replay"; // 游戏重玩
|
||||
public static readonly string ParameterContinue = "continue"; // 游戏继续
|
||||
public static readonly string ParameterAdUnitName = "ad_unit_name";
|
||||
public static readonly string ParameterAdPlacement = "ad_placement";
|
||||
public static readonly string ParameterAdCreativeId = "ad_creative_id";
|
||||
public static readonly string ParameterReviewCreativeId = "review_creative_id";
|
||||
|
||||
|
||||
// 评价参数
|
||||
public static readonly string EventRateImp = "rate_imp"; // 评价弹窗展示
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ namespace Guru
|
|||
|
||||
public static bool IsDebug { get; set; } = false;
|
||||
|
||||
private static bool _hasInited = false;
|
||||
|
||||
public static bool IsReady => _hasInited;
|
||||
private static bool _isGuruAnalyticInitOnce = false;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化Guru自打点系统 (请优先于 Firebase 初始化调用)
|
||||
|
|
@ -36,7 +34,7 @@ namespace Guru
|
|||
public static void InstallGuruAnalytics(bool isDebug = false, bool enableErrorLog = false)
|
||||
{
|
||||
|
||||
if (_hasInited) return;
|
||||
if (_isGuruAnalyticInitOnce) return;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -47,7 +45,7 @@ namespace Guru
|
|||
#endif
|
||||
string appId = IPMConfig.IPM_X_APP_ID;
|
||||
string deviceInfo = new DeviceInfoData().ToString();
|
||||
GuruAnalytics.Init(appId, deviceInfo, IsDebug, enableErrorLog); // 初始化(带Header)
|
||||
GuruAnalytics.Init(appId, deviceInfo, OnGuruAnalyticsInitComplete, IsDebug, enableErrorLog); // 初始化(带Header)
|
||||
|
||||
_hasGotFirebaseId = false;
|
||||
_hasGotAdId = false;
|
||||
|
|
@ -59,7 +57,7 @@ namespace Guru
|
|||
|
||||
UpdateAllValues();
|
||||
|
||||
_hasInited = true;
|
||||
_isGuruAnalyticInitOnce = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -79,7 +77,7 @@ namespace Guru
|
|||
if (!string.IsNullOrEmpty(IPMConfig.IPM_UID))
|
||||
{
|
||||
Debug.Log($"---[ANA] UID: {IPMConfig.IPM_UID}");
|
||||
GuruAnalytics.SetUid(IPMConfig.IPM_UID);
|
||||
GuruAnalytics.Instance.SetUid(IPMConfig.IPM_UID);
|
||||
FirebaseAnalytics.SetUserProperty(PropertyUserID, IPMConfig.IPM_UID);
|
||||
_hasGotUid = true;
|
||||
}
|
||||
|
|
@ -95,7 +93,7 @@ namespace Guru
|
|||
|
||||
if (!string.IsNullOrEmpty(IPMConfig.IPM_DEVICE_ID))
|
||||
{
|
||||
GuruAnalytics.SetDeviceId(IPMConfig.IPM_DEVICE_ID);
|
||||
GuruAnalytics.Instance.SetDeviceId(IPMConfig.IPM_DEVICE_ID);
|
||||
FirebaseAnalytics.SetUserProperty(PropertyDeviceID, IPMConfig.IPM_DEVICE_ID);
|
||||
_hasGotDeviceId = true;
|
||||
}
|
||||
|
|
@ -121,7 +119,7 @@ namespace Guru
|
|||
|
||||
if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID))
|
||||
{
|
||||
GuruAnalytics.SetAdjustId(IPMConfig.ADJUST_ID);
|
||||
GuruAnalytics.Instance.SetAdjustId(IPMConfig.ADJUST_ID);
|
||||
_hasGotAdjustId = true;
|
||||
}
|
||||
else
|
||||
|
|
@ -152,7 +150,7 @@ namespace Guru
|
|||
|
||||
if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ADID))
|
||||
{
|
||||
GuruAnalytics.SetAdId(IPMConfig.ADJUST_ADID);
|
||||
GuruAnalytics.Instance.SetAdId(IPMConfig.ADJUST_ADID);
|
||||
_hasGotAdId = true;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +169,7 @@ namespace Guru
|
|||
|
||||
if (!string.IsNullOrEmpty(IPMConfig.FIREBASE_ID))
|
||||
{
|
||||
GuruAnalytics.SetFirebaseId(IPMConfig.FIREBASE_ID);
|
||||
GuruAnalytics.Instance.SetFirebaseId(IPMConfig.FIREBASE_ID);
|
||||
_hasGotFirebaseId = true;
|
||||
}
|
||||
else
|
||||
|
|
@ -185,6 +183,8 @@ namespace Guru
|
|||
/// </summary>
|
||||
private static void FetchFirebaseId()
|
||||
{
|
||||
if (!IsFirebaseReady) return;
|
||||
|
||||
FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
|
|
@ -241,7 +241,7 @@ namespace Guru
|
|||
/// </summary>
|
||||
private static void SetAndroidId()
|
||||
{
|
||||
GuruAnalytics.SetAndroidID(DeviceIDHelper.AndroidID);
|
||||
GuruAnalytics.Instance.SetAndroidID(DeviceIDHelper.AndroidID);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ namespace Guru
|
|||
var interval = (DateTime.Now - _lastReportRateDate).TotalSeconds;
|
||||
if (interval > _reportSuccessInterval)
|
||||
{
|
||||
GuruAnalytics.ReportEventSuccessRate();
|
||||
GuruAnalytics.Instance.ReportEventSuccessRate();
|
||||
_lastReportRateDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ namespace Guru
|
|||
{
|
||||
try
|
||||
{
|
||||
GuruAnalytics.SetUserProperty(key, value);
|
||||
GuruAnalytics.Instance.SetUserProperty(key, value);
|
||||
UpdateAllValues(); // 同步所有的ID
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -309,12 +309,12 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="data"></param>
|
||||
private static void CustomLogEvent(string key, Dictionary<string, dynamic> data = null, int priority = -1)
|
||||
private static void TrackEventGuru(string key, Dictionary<string, dynamic> data = null, int priority = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (data == null) data = new Dictionary<string, dynamic>();
|
||||
GuruAnalytics.LogEvent(key, data, priority);
|
||||
GuruAnalytics.Instance.LogEvent(key, data, priority);
|
||||
UpdateAllValues(); // 同步所有的ID
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -337,7 +337,7 @@ namespace Guru
|
|||
if (Math.Abs(_tch02TargetValue - value) > 0.001d)
|
||||
{
|
||||
_tch02TargetValue = value;
|
||||
GuruAnalytics.SetTch02Value(value);
|
||||
GuruAnalytics.Instance.SetTch02Value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ namespace Guru
|
|||
if(!string.IsNullOrEmpty(scene)) data[ParameterScene] = scene; // 获取的虚拟货币或者道具的场景
|
||||
if (extra != null) data.AddRange(extra, isOverride: true);
|
||||
|
||||
LogEvent(EventEarnVirtualCurrency, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
TrackEvent(EventEarnVirtualCurrency, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
|
||||
// FB 上报收入点
|
||||
FBService.LogEvent(EventEarnVirtualCurrency, value, data);
|
||||
|
|
@ -131,7 +131,7 @@ namespace Guru
|
|||
|
||||
if(!string.IsNullOrEmpty(scene)) data[ParameterScene] = scene; // 获取的虚拟货币或者道具的场景
|
||||
|
||||
LogEvent(EventSpendVirtualCurrency, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
TrackEvent(EventSpendVirtualCurrency, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
|
||||
// FB 上报消费点
|
||||
FBService.LogEvent(EventSpendVirtualCurrency, value, data);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Guru
|
|||
};
|
||||
if (extra != null) dict.AddRange(extra, isOverride:true);
|
||||
|
||||
LogEvent(EventLevelUp, dict);
|
||||
TrackEvent(EventLevelUp, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -42,7 +42,7 @@ namespace Guru
|
|||
};
|
||||
if (extra != null) dict.AddRange(extra, isOverride:true);
|
||||
|
||||
LogEvent(EventUnlockAchievement, dict);
|
||||
TrackEvent(EventUnlockAchievement, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -53,7 +53,7 @@ namespace Guru
|
|||
[Obsolete("Obsolete method, please use <LogLevelStart> instead. will be discard in next version.")]
|
||||
public static void LevelStart(int level)
|
||||
{
|
||||
LogEvent(EventLevelStart, new Dictionary<string, object>()
|
||||
TrackEvent(EventLevelStart, new Dictionary<string, object>()
|
||||
{
|
||||
{ ParameterLevel, level },
|
||||
{ ParameterItemCategory, "main" },
|
||||
|
|
@ -91,7 +91,7 @@ namespace Guru
|
|||
dict.AddRange(extra, isOverride:true);
|
||||
}
|
||||
|
||||
LogEvent(EventLevelStart, dict);
|
||||
TrackEvent(EventLevelStart, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -131,7 +131,7 @@ namespace Guru
|
|||
|
||||
if(extra != null) dict.AddRange(extra, isOverride:true);
|
||||
|
||||
LogEvent(EventLevelEnd, dict);
|
||||
TrackEvent(EventLevelEnd, dict);
|
||||
|
||||
// if (isSuccess)
|
||||
// {
|
||||
|
|
@ -160,7 +160,7 @@ namespace Guru
|
|||
["level"] = level,
|
||||
};
|
||||
}
|
||||
LogEvent(eventName, extra, new EventSetting()
|
||||
TrackEvent(eventName, extra, new EventSetting()
|
||||
{
|
||||
EnableFirebaseAnalytics = true,
|
||||
EnableFacebookAnalytics = true,
|
||||
|
|
@ -188,7 +188,7 @@ namespace Guru
|
|||
if (extra != null)
|
||||
dict.AddRange(extra, isOverride: true);
|
||||
|
||||
LogEvent(EventLevelFirstEnd, dict);
|
||||
TrackEvent(EventLevelFirstEnd, dict);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -215,7 +215,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict.AddRange(extra, isOverride: true);
|
||||
|
||||
LogEvent(EventEarnVirtualCurrency, dict);
|
||||
TrackEvent(EventEarnVirtualCurrency, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -237,7 +237,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict.AddRange(extra, isOverride: true);
|
||||
|
||||
LogEvent(EventSpendVirtualCurrency, dict);
|
||||
TrackEvent(EventSpendVirtualCurrency, dict);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict.AddRange(extra, isOverride: true);
|
||||
|
||||
LogEvent("hit_points", dict);
|
||||
TrackEvent("hit_points", dict);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ namespace Guru
|
|||
|
||||
//--------- Extra data for IAP receipt ---------------
|
||||
|
||||
LogEvent(evtName, data);
|
||||
TrackEvent(evtName, data);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -416,7 +416,6 @@ namespace Guru
|
|||
/// Google ARO买量点
|
||||
/// </summary>
|
||||
/// <param name="impressionData">广告收入数据</param>
|
||||
/// <param name="platform">广告平台</param>
|
||||
/// <a href="https://docs.google.com/spreadsheets/d/1lFWLeOGJgq34QDBTfl6OpNh7MoI37ehGrhdbxlOrJgs/edit#gid=983654222"></a>
|
||||
/// <li>
|
||||
/// value double eg:0.002
|
||||
|
|
@ -427,25 +426,25 @@ namespace Guru
|
|||
/// ad_unit_name string 广告位名称
|
||||
/// ad_creative_id string 广告素材id
|
||||
/// </li>
|
||||
public static void ADImpression(MaxSdkBase.AdInfo impressionData, string platform = "")
|
||||
public static void ADImpression(AdImpressionData impressionData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(platform)) platform = AdMAX;
|
||||
double revenue = impressionData.Revenue;
|
||||
LogEvent(EventAdImpression, new Dictionary<string, dynamic>()
|
||||
TrackEvent(EventAdImpression, new Dictionary<string, dynamic>()
|
||||
{
|
||||
[ParameterValue] = revenue,
|
||||
[ParameterCurrency] = USD,
|
||||
[ParameterAdPlatform] = platform,
|
||||
[ParameterAdSource] = impressionData.NetworkName,
|
||||
[ParameterAdFormat] = impressionData.AdFormat,
|
||||
[ParameterAdUnitName] = impressionData.AdUnitIdentifier,
|
||||
[ParameterAdCreativeId] = impressionData.CreativeIdentifier,
|
||||
[ParameterValue] = impressionData.value,
|
||||
[ParameterCurrency] = impressionData.currency,
|
||||
[ParameterAdPlatform] = impressionData.ad_platform,
|
||||
[ParameterAdSource] = impressionData.ad_source,
|
||||
[ParameterAdFormat] = impressionData.ad_format,
|
||||
[ParameterAdUnitName] = impressionData.ad_unit_name,
|
||||
[ParameterAdPlacement] = impressionData.ad_placement,
|
||||
[ParameterAdCreativeId] = impressionData.ad_creative_id,
|
||||
[ParameterReviewCreativeId] = impressionData.review_creative_id,
|
||||
});
|
||||
}
|
||||
|
||||
public static void TchAdAbnormalEvent(double value)
|
||||
{
|
||||
LogEvent(EventTchAdRevAbnormal, new Dictionary<string, dynamic>()
|
||||
TrackEvent(EventTchAdRevAbnormal, new Dictionary<string, dynamic>()
|
||||
{
|
||||
{ ParameterAdPlatform, AdMAX },
|
||||
{ ParameterCurrency, USD },
|
||||
|
|
@ -470,7 +469,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict = GuruSDKUtils.MergeDictionary(dict, extra);
|
||||
|
||||
LogEvent(EventIAPImp, dict);
|
||||
TrackEvent(EventIAPImp, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -486,7 +485,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict = GuruSDKUtils.MergeDictionary(dict, extra);
|
||||
|
||||
LogEvent(EventIAPClose, dict);
|
||||
TrackEvent(EventIAPClose, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -512,7 +511,7 @@ namespace Guru
|
|||
};
|
||||
if(extra != null) dict = GuruSDKUtils.MergeDictionary(dict, extra);
|
||||
|
||||
LogEvent(EventIAPClick, dict);
|
||||
TrackEvent(EventIAPClick, dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -543,7 +542,7 @@ namespace Guru
|
|||
if(!string.IsNullOrEmpty(offerId))
|
||||
dict["basePlan"] = offerId;
|
||||
|
||||
LogEvent(EventIAPReturnTrue, dict, new EventSetting()
|
||||
TrackEvent(EventIAPReturnTrue, dict, new EventSetting()
|
||||
{
|
||||
EnableFirebaseAnalytics = true,
|
||||
EnableAdjustAnalytics = true,
|
||||
|
|
@ -559,7 +558,7 @@ namespace Guru
|
|||
/// <param name="failReason"></param>
|
||||
internal static void IAPRetFalse(string itemCategory, string productId, string failReason)
|
||||
{
|
||||
LogEvent(EventIAPReturnFalse, new Dictionary<string, object>()
|
||||
TrackEvent(EventIAPReturnFalse, new Dictionary<string, object>()
|
||||
{
|
||||
{ ParameterItemCategory, itemCategory },
|
||||
{ ParameterItemName, productId },
|
||||
|
|
@ -576,7 +575,7 @@ namespace Guru
|
|||
/// <param name="currency">币种</param>
|
||||
public static void FirstIAP(string itemName, double value, string currency)
|
||||
{
|
||||
LogEvent(EventIAPFirst, new Dictionary<string, object>()
|
||||
TrackEvent(EventIAPFirst, new Dictionary<string, object>()
|
||||
{
|
||||
{ ParameterItemName, itemName },
|
||||
{ ParameterValue, value },
|
||||
|
|
@ -597,7 +596,7 @@ namespace Guru
|
|||
if (productName.Contains(".")) productName = productName.Replace(".", "_");
|
||||
|
||||
string eventName = $"iap_{productName}";
|
||||
LogEvent(eventName, new Dictionary<string, object>()
|
||||
TrackEvent(eventName, new Dictionary<string, object>()
|
||||
{
|
||||
{ ParameterItemName, itemName },
|
||||
{ ParameterValue, value },
|
||||
|
|
@ -724,10 +723,8 @@ namespace Guru
|
|||
["sandbox"] = isSandbox? "true": "false"
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 上报Firebase + 自打点
|
||||
LogEvent(eventName, dict, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
TrackEvent(eventName, dict, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
|
||||
// 上报 Adjust 支付事件
|
||||
LogAdjustRevenueEvent(eventName, value, productId, orderId, purchaseToken, receipt, dict);
|
||||
|
|
@ -746,7 +743,7 @@ namespace Guru
|
|||
if (data == null) return;
|
||||
data["country"] = IPMConfig.IPM_COUNTRY_CODE;
|
||||
data["network"] = Application.internetReachability.ToString();
|
||||
LogEvent(EventDevAudit, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
TrackEvent(EventDevAudit, data, new EventSetting() { EnableFirebaseAnalytics = true });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
|
|
@ -16,83 +18,112 @@ namespace Guru
|
|||
{
|
||||
public class EventSetting
|
||||
{
|
||||
public bool EnableFirebaseAnalytics = false;
|
||||
public bool EnableAdjustAnalytics = false;
|
||||
public bool EnableFacebookAnalytics = false;
|
||||
public bool EnableFirebaseAnalytics;
|
||||
public bool EnableAdjustAnalytics;
|
||||
public bool EnableFacebookAnalytics;
|
||||
public bool EnableGuruAnalytics;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"EvenSetting: firebase:{EnableFirebaseAnalytics}, adjust:{EnableAdjustAnalytics}, facebook:{EnableFacebookAnalytics}, guru:{EnableGuruAnalytics}";
|
||||
}
|
||||
|
||||
private static EventSetting _defaultEventSetting;
|
||||
public static EventSetting GetDefaultSetting()
|
||||
{
|
||||
return new EventSetting()
|
||||
{
|
||||
EnableFirebaseAnalytics = true,
|
||||
EnableFacebookAnalytics = true,
|
||||
EnableAdjustAnalytics = true,
|
||||
EnableGuruAnalytics = true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _isInited; //Analytics是否初始化完成
|
||||
private static EventSetting DefaultEventSetting => EventSetting.GetDefaultSetting();
|
||||
|
||||
private static bool _isInitOnce; //Analytics是否初始化完成
|
||||
public static bool EnableDebugAnalytics; //允许Debug包上报打点
|
||||
|
||||
public static bool IsDebugMode => PlatformUtil.IsDebug();
|
||||
private static bool IsFirebaseReady => FirebaseUtil.IsFirebaseInitialized;
|
||||
|
||||
private static bool IsEnable
|
||||
private static bool IsReady
|
||||
{
|
||||
get
|
||||
{
|
||||
//Firebase服务没有初始化完成不上报打点
|
||||
if (!FirebaseUtil.IsFirebaseInitialized)
|
||||
return false;
|
||||
|
||||
//Analytics没有初始化不上报打点
|
||||
if (!_isInited)
|
||||
return false;
|
||||
if (!_isInitOnce) return false;
|
||||
|
||||
//Firebase服务没有初始化完成不上报打点
|
||||
if (!IsFirebaseReady) return false;
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
//开发环境打点不上报
|
||||
if (IsDebugMode && !EnableDebugAnalytics)
|
||||
return false;
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static AdjustEventDriver _adjustEventDriver;
|
||||
private static FBEventDriver _fbEventDriver;
|
||||
private static FirebaseEventDriver _firebaseEventDriver;
|
||||
private static GuruEventDriver _guruEventDriver;
|
||||
|
||||
|
||||
#region 初始化
|
||||
|
||||
public static void InitAnalytics()
|
||||
{
|
||||
if (_isInited) return;
|
||||
_isInited = true;
|
||||
if (_isInitOnce) return;
|
||||
_isInitOnce = true;
|
||||
|
||||
// -------- 初始化 Exception ----------
|
||||
CrashlyticsAgent.Install();
|
||||
_adjustEventDriver = new AdjustEventDriver();
|
||||
_fbEventDriver = new FBEventDriver();
|
||||
_firebaseEventDriver = new FirebaseEventDriver();
|
||||
_guruEventDriver = new GuruEventDriver();
|
||||
|
||||
// ------- 初始化自打点 ----------
|
||||
InstallGuruAnalytics(IsDebug);
|
||||
|
||||
if (_defaultEventSetting == null)
|
||||
{
|
||||
var analyticsSetting = GuruSettings.Instance.AnalyticsSetting;
|
||||
_defaultEventSetting = new EventSetting
|
||||
{
|
||||
EnableFirebaseAnalytics = analyticsSetting.EnalbeFirebaseAnalytics,
|
||||
EnableFacebookAnalytics = analyticsSetting.EnalbeFacebookAnalytics,
|
||||
EnableAdjustAnalytics = analyticsSetting.EnalbeAdjustAnalytics
|
||||
};
|
||||
}
|
||||
|
||||
FirebaseUtil.onInitComplete += OnFirebaseCompleted;
|
||||
}
|
||||
|
||||
private static void OnFirebaseCompleted(bool success)
|
||||
{
|
||||
FirebaseUtil.onInitComplete -= OnFirebaseCompleted;
|
||||
|
||||
if (success)
|
||||
{
|
||||
Crashlytics.IsCrashlyticsCollectionEnabled = true;
|
||||
if (_defaultEventSetting.EnableFirebaseAnalytics)
|
||||
public static void OnFirebaseInitCompleted()
|
||||
{
|
||||
Debug.Log($"[SDK] --- Analytics Init After FirebaseReady:{IsFirebaseReady}");
|
||||
|
||||
// -------- 初始化 Crashlytics ----------
|
||||
CrashlyticsAgent.Init();
|
||||
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
|
||||
FirebaseAnalytics.SetSessionTimeoutDuration(new TimeSpan(0, 30, 0));
|
||||
SetUserProperty(FirebaseAnalytics.UserPropertySignUpMethod, "Google");
|
||||
SetUserProperty(PropertyDeviceID, IPMConfig.IPM_DEVICE_ID);
|
||||
// SetUserProperty(PropertyFirstOpenTime, FirstOpenTime);
|
||||
|
||||
_firebaseEventDriver.TriggerFlush();
|
||||
}
|
||||
|
||||
|
||||
public static void OnFBInitComplete()
|
||||
{
|
||||
_fbEventDriver.TriggerFlush();
|
||||
}
|
||||
|
||||
public static void OnAdjustInitComplete()
|
||||
{
|
||||
_adjustEventDriver.TriggerFlush();
|
||||
}
|
||||
|
||||
private static void OnGuruAnalyticsInitComplete()
|
||||
{
|
||||
_guruEventDriver.TriggerFlush();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 屏幕(场景)名称
|
||||
|
|
@ -100,9 +131,9 @@ namespace Guru
|
|||
public static void SetCurrentScreen(string screenName, string className)
|
||||
{
|
||||
Log.I(TAG,$"SetCurrentScreen -> screenName:{screenName}, className:{className}");
|
||||
GuruAnalytics.SetScreen(screenName);
|
||||
GuruAnalytics.Instance.SetScreen(screenName);
|
||||
|
||||
if (!IsEnable) return;
|
||||
if (!IsReady) return;
|
||||
FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventScreenView,
|
||||
new Parameter(FirebaseAnalytics.ParameterScreenClass, className),
|
||||
new Parameter(FirebaseAnalytics.ParameterScreenName, screenName)
|
||||
|
|
@ -120,7 +151,7 @@ namespace Guru
|
|||
public static void SetUserIDProperty(string userID)
|
||||
{
|
||||
Log.I(TAG,$"SetUserIDProperty -> userID:{userID}");
|
||||
if (!IsEnable) return;
|
||||
if (!IsReady) return;
|
||||
|
||||
FirebaseAnalytics.SetUserId(userID);
|
||||
}
|
||||
|
|
@ -132,7 +163,7 @@ namespace Guru
|
|||
{
|
||||
Log.I(TAG,$"SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}");
|
||||
|
||||
if (!IsEnable)
|
||||
if (!IsReady)
|
||||
return;
|
||||
|
||||
FirebaseAnalytics.SetUserProperty(propertyName, propertyValue);
|
||||
|
|
@ -143,111 +174,61 @@ namespace Guru
|
|||
|
||||
#region 打点上报
|
||||
|
||||
/// <summary>
|
||||
/// 打点上报
|
||||
/// </summary>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="eventSetting"></param>
|
||||
internal static void LogEvent(string eventName, EventSetting eventSetting = null, int priority = -1)
|
||||
{
|
||||
Log.I(TAG, $"eventName:{eventName}");
|
||||
CustomLogEvent(eventName, null, priority); // 自定义打点上报
|
||||
CheckLogCache(eventName, null, eventSetting); // log缓存和消费
|
||||
|
||||
if (!IsEnable) return;
|
||||
|
||||
eventSetting ??= _defaultEventSetting;
|
||||
|
||||
if (eventSetting.EnableFirebaseAnalytics)
|
||||
{
|
||||
FirebaseAnalytics.LogEvent(eventName);
|
||||
}
|
||||
|
||||
if (eventSetting.EnableAdjustAnalytics)
|
||||
{
|
||||
Adjust.trackEvent(CreateAdjustEvent(eventName));
|
||||
}
|
||||
|
||||
if (eventSetting.EnableFacebookAnalytics)
|
||||
{
|
||||
FBService.LogEvent(eventName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打点上报 (带参数)
|
||||
/// </summary>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="extras"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="eventSetting"></param>
|
||||
/// <param name="priority"></param>
|
||||
internal static void LogEvent(string eventName, Dictionary<string, dynamic> extras, EventSetting eventSetting = null, int priority = -1)
|
||||
internal static void TrackEvent(string eventName, Dictionary<string, dynamic> data,
|
||||
EventSetting eventSetting = null, int priority = -1)
|
||||
{
|
||||
CustomLogEvent(eventName, extras, priority); // 自定义打点上报
|
||||
CheckLogCache(eventName, extras, eventSetting); // log缓存和消费
|
||||
|
||||
if (!IsEnable) return;
|
||||
|
||||
if (extras == null)
|
||||
if (!_isInitOnce)
|
||||
{
|
||||
LogEvent(eventName, eventSetting, priority); // 防空判定
|
||||
return;
|
||||
throw new Exception($"【SDK] Analytics did not initialized, Call <Analytics.{nameof(InitAnalytics)}()> first!");
|
||||
}
|
||||
|
||||
string paramStr = string.Join(",", extras);
|
||||
Log.I(TAG, $"eventName:{eventName}, params:{paramStr}");
|
||||
if (eventSetting == null) eventSetting = DefaultEventSetting;
|
||||
|
||||
if (eventSetting == null) eventSetting = _defaultEventSetting;
|
||||
var dataStr = "";
|
||||
if (data != null) dataStr = JsonParser.ToJson(data);
|
||||
Debug.Log($"{TAG} --- [SDK] TrackEvent: {eventName} | priority: {priority} | data:{dataStr} | eventSetting: {eventSetting}");
|
||||
|
||||
try
|
||||
{
|
||||
// 填充相关的追踪事件
|
||||
if (eventSetting.EnableGuruAnalytics)
|
||||
{
|
||||
_guruEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority));
|
||||
}
|
||||
if (eventSetting.EnableFirebaseAnalytics)
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
foreach (var kv in extras)
|
||||
{
|
||||
if(kv.Value is string strValue)
|
||||
parameters.Add(new Parameter(kv.Key, strValue));
|
||||
else if (kv.Value is bool boolValue)
|
||||
parameters.Add(new Parameter(kv.Key, boolValue ? "true" : "false"));
|
||||
else if (kv.Value is int intValue)
|
||||
parameters.Add(new Parameter(kv.Key, intValue));
|
||||
else if (kv.Value is long longValue)
|
||||
parameters.Add(new Parameter(kv.Key, longValue));
|
||||
else if (kv.Value is float floatValue)
|
||||
parameters.Add(new Parameter(kv.Key, floatValue));
|
||||
else if (kv.Value is double doubleValue)
|
||||
parameters.Add(new Parameter(kv.Key, doubleValue));
|
||||
else if (kv.Value is decimal decimalValue)
|
||||
parameters.Add(new Parameter(kv.Key, decimal.ToDouble(decimalValue)));
|
||||
else
|
||||
parameters.Add(new Parameter(kv.Key, kv.Value.ToString()));
|
||||
_firebaseEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority));
|
||||
}
|
||||
|
||||
FirebaseAnalytics.LogEvent(eventName, parameters.ToArray());
|
||||
}
|
||||
|
||||
Dictionary<string, object> dict = new Dictionary<string, object>();
|
||||
GuruSDKUtils.MergeDictionary(dict, extras);
|
||||
|
||||
if (eventSetting.EnableAdjustAnalytics)
|
||||
{
|
||||
AdjustEvent adjustEvent = Analytics.CreateAdjustEvent(eventName);
|
||||
if (adjustEvent != null)
|
||||
_adjustEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority));
|
||||
}
|
||||
if (eventSetting.EnableFacebookAnalytics)
|
||||
{
|
||||
if (dict.Count > 0)
|
||||
{
|
||||
foreach (var kv in dict)
|
||||
{
|
||||
adjustEvent.AddEventParameter(kv.Key, kv.Value.ToString());
|
||||
_fbEventDriver.Append(new TrackingEvent(eventName, data, eventSetting, priority));
|
||||
}
|
||||
}
|
||||
Adjust.trackEvent(adjustEvent);
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (FirebaseUtil.IsReady)
|
||||
{
|
||||
Crashlytics.LogException(ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Catch Error: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventSetting.EnableFacebookAnalytics)
|
||||
{
|
||||
FBService.LogEvent(eventName, null, dict);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报 Adjust 事件
|
||||
|
|
@ -300,14 +281,7 @@ namespace Guru
|
|||
/// <param name="priority"></param>
|
||||
public static void Track(string key, Dictionary<string, dynamic> data = null, EventSetting setting = null, int priority = -1)
|
||||
{
|
||||
if (null != data)
|
||||
{
|
||||
LogEvent(key, data, setting, priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogEvent(key, setting, priority);
|
||||
}
|
||||
TrackEvent(key, data, setting, priority);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -318,7 +292,7 @@ namespace Guru
|
|||
/// <param name="isException"></param>
|
||||
public static void LogCrashlytics(string msg, bool isException = true)
|
||||
{
|
||||
if (!_isInited) return;
|
||||
if (!_isInitOnce) return;
|
||||
if (isException)
|
||||
{
|
||||
LogCrashlytics(new Exception(msg));
|
||||
|
|
@ -332,7 +306,7 @@ namespace Guru
|
|||
|
||||
public static void LogCrashlytics(Exception exp)
|
||||
{
|
||||
if (!_isInited) return;
|
||||
if (!_isInitOnce) return;
|
||||
CrashlyticsAgent.LogException(exp);
|
||||
}
|
||||
|
||||
|
|
@ -340,76 +314,58 @@ namespace Guru
|
|||
|
||||
#region 打点缓存
|
||||
|
||||
private static Queue<SavedLog> _savedLogs;
|
||||
private static Queue<TrackingEvent> _savedLogs;
|
||||
|
||||
internal static Queue<SavedLog> SavedLogs
|
||||
internal static Queue<TrackingEvent> SavedLogs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_savedLogs == null) _savedLogs = new Queue<SavedLog>(20);
|
||||
if (_savedLogs == null) _savedLogs = new Queue<TrackingEvent>(20);
|
||||
return _savedLogs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void CheckLogCache(string key, Dictionary<string, dynamic> data = null, EventSetting setting = null, int priority = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_isInited)
|
||||
{
|
||||
if (data == null) data = new Dictionary<string, dynamic>();
|
||||
data["log_stamp"] = TimeUtil.GetCurrentTimeStamp().ToString();
|
||||
SavedLogs.Enqueue(new SavedLog(key, data, setting, priority));
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = SavedLogs.Count;
|
||||
if (len > 0)
|
||||
{
|
||||
while (SavedLogs.Count > 0)
|
||||
{
|
||||
var log = SavedLogs.Dequeue();
|
||||
LogEvent(log.key, log.data, log.setting, log.priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Crashlytics.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal class SavedLog
|
||||
public class TrackingEvent
|
||||
{
|
||||
public string key;
|
||||
public string eventName;
|
||||
public int priority;
|
||||
public Dictionary<string, dynamic> data;
|
||||
public Analytics.EventSetting setting;
|
||||
|
||||
public SavedLog()
|
||||
public TrackingEvent()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存打点信息
|
||||
/// </summary>
|
||||
/// <param name="_key"></param>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="_data"></param>
|
||||
/// <param name="_setting"></param>
|
||||
/// <param name="_priority"></param>
|
||||
public SavedLog(string _key, Dictionary<string, dynamic> _data = null, Analytics.EventSetting _setting = null, int _priority = -1)
|
||||
public TrackingEvent(string eventName, Dictionary<string, dynamic> data = null, Analytics.EventSetting setting = null, int priority = -1)
|
||||
{
|
||||
key = _key;
|
||||
data = _data;
|
||||
setting = _setting;
|
||||
priority = _priority;
|
||||
this.eventName = eventName;
|
||||
this.data = data;
|
||||
this.setting = setting;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
Analytics.TrackEvent(eventName, data, setting, priority);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"eventName: {eventName}, data: {data}, setting: {setting}, priority: {priority}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d13f245a2ea24c8ebdb957ad4ba79ca4
|
||||
timeCreated: 1721908201
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
namespace Guru
|
||||
{
|
||||
public abstract class AbstractEventDriver: IEventDriver
|
||||
{
|
||||
private GuruEventBuffer _buffer = new GuruEventBuffer();
|
||||
|
||||
// Firebase 是否可用
|
||||
private bool _isDriverReady = false;
|
||||
|
||||
public void TriggerFlush()
|
||||
{
|
||||
_isDriverReady = true;
|
||||
FlushAll();
|
||||
}
|
||||
public void Append(TrackingEvent trackingEvent)
|
||||
{
|
||||
if (_isDriverReady)
|
||||
{
|
||||
FlushTrackingEvent(trackingEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer.Push(trackingEvent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void FlushAll()
|
||||
{
|
||||
while(_buffer.Pop(out var trackingEvent))
|
||||
{
|
||||
FlushTrackingEvent(trackingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件
|
||||
/// </summary>
|
||||
/// <param name="trackEvent"></param>
|
||||
protected abstract void FlushTrackingEvent(TrackingEvent trackEvent);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fe02e66845f64aafa94654814822930a
|
||||
timeCreated: 1721916181
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using com.adjust.sdk;
|
||||
public class AdjustEventDriver : AbstractEventDriver
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送事件
|
||||
/// </summary>
|
||||
/// <param name="trackingEvent"></param>
|
||||
protected override void FlushTrackingEvent(TrackingEvent trackingEvent)
|
||||
{
|
||||
var eventName = trackingEvent.eventName;
|
||||
var data = trackingEvent.data;
|
||||
AdjustEvent adjustEvent = Analytics.CreateAdjustEvent(eventName);
|
||||
if (adjustEvent != null)
|
||||
{
|
||||
UnityEngine.Debug.Log($"[SDK] --- Adjust logEvent: {trackingEvent}");
|
||||
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
foreach (var kv in data)
|
||||
{
|
||||
adjustEvent.AddEventParameter(kv.Key, ((object)kv.Value).ToString());
|
||||
}
|
||||
}
|
||||
Adjust.trackEvent(adjustEvent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f064544085c8401d988b9eae91bd79b1
|
||||
timeCreated: 1721910840
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
public class FBEventDriver: AbstractEventDriver
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送事件
|
||||
/// </summary>
|
||||
/// <param name="trackingEvent"></param>
|
||||
protected override void FlushTrackingEvent(TrackingEvent trackingEvent)
|
||||
{
|
||||
var eventName = trackingEvent.eventName;
|
||||
var data = trackingEvent.data;
|
||||
Debug.Log($"[SDK] --- FB logEvent: {trackingEvent}");
|
||||
|
||||
FBService.LogEvent(eventName, null, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 305a62f1c0fe4a16b7c9101264be523b
|
||||
timeCreated: 1721910530
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using Firebase.Analytics;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Firebase 专用
|
||||
/// </summary>
|
||||
internal class FirebaseEventDriver : AbstractEventDriver
|
||||
{
|
||||
|
||||
protected override void FlushTrackingEvent(TrackingEvent trackingEvent)
|
||||
{
|
||||
var eventName = trackingEvent.eventName;
|
||||
var data = trackingEvent.data;
|
||||
|
||||
Debug.Log($"[SDK] --- Firebase logEvent: {trackingEvent}");
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
foreach (var kv in data)
|
||||
{
|
||||
if(kv.Value is string strValue)
|
||||
parameters.Add(new Parameter(kv.Key, strValue));
|
||||
else if (kv.Value is bool boolValue)
|
||||
parameters.Add(new Parameter(kv.Key, boolValue ? "true" : "false"));
|
||||
else if (kv.Value is int intValue)
|
||||
parameters.Add(new Parameter(kv.Key, intValue));
|
||||
else if (kv.Value is long longValue)
|
||||
parameters.Add(new Parameter(kv.Key, longValue));
|
||||
else if (kv.Value is float floatValue)
|
||||
parameters.Add(new Parameter(kv.Key, floatValue));
|
||||
else if (kv.Value is double doubleValue)
|
||||
parameters.Add(new Parameter(kv.Key, doubleValue));
|
||||
else if (kv.Value is decimal decimalValue)
|
||||
parameters.Add(new Parameter(kv.Key, decimal.ToDouble(decimalValue)));
|
||||
else
|
||||
parameters.Add(new Parameter(kv.Key, kv.Value.ToString()));
|
||||
}
|
||||
|
||||
FirebaseAnalytics.LogEvent(eventName, parameters.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
FirebaseAnalytics.LogEvent(eventName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a4c2262ab86431ba6d5961e7453d60f
|
||||
timeCreated: 1721905429
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System.Collections.Concurrent;
|
||||
public class GuruEventBuffer
|
||||
{
|
||||
private ConcurrentQueue<TrackingEvent> _eventQueue;
|
||||
|
||||
public int Count => _eventQueue?.Count ?? -1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public GuruEventBuffer()
|
||||
{
|
||||
_eventQueue = new ConcurrentQueue<TrackingEvent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 入栈
|
||||
/// </summary>
|
||||
/// <param name="trackEvent"></param>
|
||||
public void Push(TrackingEvent trackEvent)
|
||||
{
|
||||
_eventQueue.Enqueue(trackEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出栈
|
||||
/// </summary>
|
||||
/// <param name="trackingEvent"></param>
|
||||
/// <returns></returns>
|
||||
public bool Pop(out TrackingEvent trackingEvent)
|
||||
{
|
||||
return _eventQueue.TryDequeue(out trackingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IEventDriver
|
||||
{
|
||||
void TriggerFlush();
|
||||
void Append(TrackingEvent trackingEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f6dd65ae849944c59be2182eb64db34a
|
||||
timeCreated: 1721899117
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace Guru
|
||||
{
|
||||
public class GuruEventDriver: AbstractEventDriver
|
||||
{
|
||||
protected override void FlushTrackingEvent(TrackingEvent trackingEvent)
|
||||
{
|
||||
GuruAnalytics.Instance.LogEvent(trackingEvent.eventName, trackingEvent.data, trackingEvent.priority);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3fee5c262ca43c387ce76d52fb149c8
|
||||
timeCreated: 1721908696
|
||||
|
|
@ -58,7 +58,7 @@ namespace Guru
|
|||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
PlayerPrefs.SetString(nameof(FirebaseId), value);
|
||||
GuruAnalytics.SetFirebaseId(value);
|
||||
GuruAnalytics.Instance.SetFirebaseId(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ namespace Guru
|
|||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
PlayerPrefs.SetString(nameof(AdjustId), value);
|
||||
GuruAnalytics.SetAdjustId(value);
|
||||
GuruAnalytics.Instance.SetAdjustId(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ namespace Guru
|
|||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
PlayerPrefs.SetString(nameof(GoogleAdId), value);
|
||||
GuruAnalytics.SetAdId(value);
|
||||
GuruAnalytics.Instance.SetAdId(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,30 @@
|
|||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Facebook.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
[MonoSingleton(EMonoSingletonType.CreateOnNewGameObject, false)]
|
||||
public class FBService : MonoSingleton<FBService>
|
||||
{
|
||||
public static readonly string LOG_TAG = "FB";
|
||||
private const string Tag = "[FB]";
|
||||
private bool _isInitOnce;
|
||||
private Action _onInitComplete;
|
||||
|
||||
public void StartService()
|
||||
{
|
||||
if (!FB.IsInitialized)
|
||||
public void StartService(Action onInitComplete)
|
||||
{
|
||||
if(_isInitOnce) return;
|
||||
_isInitOnce = true;
|
||||
|
||||
_onInitComplete = onInitComplete;
|
||||
// Initialize the Facebook SDK
|
||||
FB.Init(InitCallback, OnHideUnity);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already initialized, signal an app activation App Event
|
||||
FB.ActivateApp();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitCallback()
|
||||
{
|
||||
if (FB.IsInitialized)
|
||||
{
|
||||
|
||||
// Signal an app activation App Event
|
||||
FB.ActivateApp();
|
||||
FB.Mobile.SetAdvertiserIDCollectionEnabled(true);
|
||||
|
|
@ -34,11 +32,7 @@ namespace Guru
|
|||
#if UNITY_IOS
|
||||
FB.Mobile.SetAdvertiserTrackingEnabled(true);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.E(LOG_TAG, "Failed to Initialize the Facebook SDK");
|
||||
}
|
||||
_onInitComplete?.Invoke();
|
||||
}
|
||||
|
||||
private void OnHideUnity(bool isGameShown)
|
||||
|
|
@ -81,13 +75,13 @@ namespace Guru
|
|||
}
|
||||
|
||||
|
||||
private static bool IsAvailable
|
||||
public static bool IsAvailable
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!FB.IsInitialized)
|
||||
{
|
||||
Debug.LogError("[FB] FB is not initialized, please call <FBService.StartService> first.");
|
||||
Debug.LogError($"{Tag} FB is not initialized, please call <FBService.StartService> first.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ namespace Guru
|
|||
public static partial class FirebaseUtil
|
||||
{
|
||||
private static readonly string LOG_TAG = "Firebase";
|
||||
private static bool _isDebug = false;
|
||||
private static bool _isReady = false;
|
||||
public static bool IsReady => _isReady;
|
||||
|
||||
|
|
@ -19,14 +18,13 @@ namespace Guru
|
|||
|
||||
public static Action<bool> OnFirebaseAuthResult;
|
||||
public static Action<bool> OnUserAuthResult;
|
||||
public static Action<string> OnAdjustDeeplinkCallback = null;
|
||||
|
||||
|
||||
|
||||
public static void InitFirebase(Action callback, bool isDebug = false)
|
||||
public static void InitFirebase(Action callback)
|
||||
{
|
||||
_isReady = false;
|
||||
_isDebug = isDebug;
|
||||
Analytics.InitAnalytics(); // 打点提前初始化
|
||||
// Analytics.InitAnalytics(); // 打点提前初始化
|
||||
|
||||
// Loom.StartUp(); // 确保主线程开启
|
||||
|
||||
|
|
@ -103,6 +101,7 @@ namespace Guru
|
|||
FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
|
||||
if (task.IsCompleted && !string.IsNullOrEmpty(task.Result))
|
||||
{
|
||||
// 保存本地ID备份
|
||||
|
|
@ -119,11 +118,14 @@ namespace Guru
|
|||
string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId;
|
||||
|
||||
if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID))
|
||||
{
|
||||
ReportAdjustId(IPMConfig.ADJUST_ID); // 二次启动后,若有值则立即上报属性
|
||||
|
||||
AdjustService.StartService(appToken, fbAppId, OnGetAdjustId, OnAdjustDeeplinkCallback);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
AdjustService.StartService(appToken, fbAppId, adjustId =>
|
||||
private static void OnGetAdjustId(string adjustId)
|
||||
{
|
||||
// 获取 ADID
|
||||
if (string.IsNullOrEmpty(adjustId))
|
||||
|
|
@ -135,9 +137,8 @@ namespace Guru
|
|||
IPMConfig.ADJUST_ID = adjustId;
|
||||
}
|
||||
ReportAdjustId(adjustId);
|
||||
});
|
||||
|
||||
});
|
||||
Analytics.OnAdjustInitComplete();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,8 @@ namespace Guru
|
|||
public static class CrashlyticsAgent
|
||||
{
|
||||
private static bool _initOnce;
|
||||
private static bool _isReady;
|
||||
private static bool IsFirebaseReady => FirebaseUtil.IsFirebaseInitialized;
|
||||
|
||||
private static Queue<Exception> _expCache;
|
||||
private static bool _hasSetUser = false;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -32,46 +31,19 @@ namespace Guru
|
|||
LogType.Assert,
|
||||
};
|
||||
|
||||
public static void Install()
|
||||
public static void Init()
|
||||
{
|
||||
if (_initOnce) return;
|
||||
_initOnce = true;
|
||||
_expCache = new Queue<Exception>(20);
|
||||
|
||||
Application.logMessageReceived -= OnReceivedMessage;
|
||||
Application.logMessageReceived += OnReceivedMessage;
|
||||
|
||||
// Application.logMessageReceivedThreaded -= OnReceivedMessage;
|
||||
// Application.logMessageReceivedThreaded += OnReceivedMessage;
|
||||
|
||||
if (FirebaseUtil.IsReady)
|
||||
{
|
||||
OnFirebaseComplete(true);
|
||||
return;
|
||||
}
|
||||
|
||||
FirebaseUtil.onInitComplete -= OnFirebaseComplete;
|
||||
FirebaseUtil.onInitComplete += OnFirebaseComplete;
|
||||
}
|
||||
|
||||
private static void OnFirebaseComplete(bool success)
|
||||
{
|
||||
FirebaseUtil.onInitComplete -= OnFirebaseComplete;
|
||||
if (success)
|
||||
{
|
||||
_isReady = true;
|
||||
Crashlytics.IsCrashlyticsCollectionEnabled = true;
|
||||
if (_expCache != null && _expCache.Count > 0)
|
||||
{
|
||||
while (_expCache.Count > 0)
|
||||
{
|
||||
LogException(_expCache.Dequeue());
|
||||
}
|
||||
_expCache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static string ToLogTypeString(LogType type)
|
||||
{
|
||||
switch (type)
|
||||
|
|
@ -101,14 +73,8 @@ namespace Guru
|
|||
|
||||
public static void LogException(Exception ex)
|
||||
{
|
||||
if (!_isReady)
|
||||
{
|
||||
Install();
|
||||
_expCache.Enqueue(ex);
|
||||
return;
|
||||
}
|
||||
if (!IsFirebaseReady) return;
|
||||
Crashlytics.LogException(ex);
|
||||
// CheckSetUser();
|
||||
}
|
||||
|
||||
public static void LogException(string msg)
|
||||
|
|
@ -118,15 +84,14 @@ namespace Guru
|
|||
|
||||
public static void Log(string msg)
|
||||
{
|
||||
if (!_isReady) return;
|
||||
if (!IsFirebaseReady) return;
|
||||
Crashlytics.Log(msg);
|
||||
// CheckSetUser();
|
||||
}
|
||||
|
||||
|
||||
public static void SetCustomKey(string key, string value)
|
||||
{
|
||||
if (!_isReady) return;
|
||||
if (!IsFirebaseReady) return;
|
||||
Crashlytics.SetCustomKey(key, value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,9 +140,13 @@ namespace Guru
|
|||
public class AnalyticsSetting
|
||||
{
|
||||
[SerializeField] private int levelEndSuccessNum = 50;
|
||||
[Obsolete("Will not use in next version", false)]
|
||||
[SerializeField] private bool enalbeFirebaseAnalytics = true;
|
||||
[Obsolete("Will not use in next version", false)]
|
||||
[SerializeField] private bool enalbeFacebookAnalytics = true;
|
||||
[Obsolete("Will not use in next version", false)]
|
||||
[SerializeField] private bool enalbeAdjustAnalytics = true;
|
||||
|
||||
[SerializeField] internal List<AdjustEvent> adjustEventList;
|
||||
|
||||
public int LevelEndSuccessNum => levelEndSuccessNum;
|
||||
|
|
|
|||
|
|
@ -1132,7 +1132,7 @@ namespace Guru
|
|||
|
||||
private void ReportGoogleOrderLost(GoogleOrderData data)
|
||||
{
|
||||
Analytics.LogEvent("google_order_lost", new Dictionary<string, dynamic>()
|
||||
Analytics.TrackEvent("google_order_lost", new Dictionary<string, dynamic>()
|
||||
{
|
||||
["data"] = data.ToString(),
|
||||
}, new Analytics.EventSetting()
|
||||
|
|
@ -1144,7 +1144,7 @@ namespace Guru
|
|||
|
||||
private void ReportAppleOrderLost(AppleOrderData data)
|
||||
{
|
||||
Analytics.LogEvent("apple_order_lost", new Dictionary<string, dynamic>()
|
||||
Analytics.TrackEvent("apple_order_lost", new Dictionary<string, dynamic>()
|
||||
{
|
||||
["data"] = data.ToString(),
|
||||
}, new Analytics.EventSetting()
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ namespace Guru
|
|||
MinimumFetchInternalInMilliseconds = (ulong)(_fetchIntervalHours * 60 * 60 * 1000)
|
||||
});
|
||||
|
||||
_firebaseRemote.OnConfigUpdateListener += OnConfigUpdatedHandler;
|
||||
|
||||
// 设置默认值
|
||||
AppendDefaultValues(defaults);
|
||||
_initOnce = true;
|
||||
|
|
@ -94,7 +96,8 @@ namespace Guru
|
|||
// 监听事件合集
|
||||
_changeEvents = new Dictionary<string, Action<string,string>>(30);
|
||||
|
||||
FetchAllConfigs();
|
||||
// 立即拉取所有的配置
|
||||
FetchAllConfigsImmediately();
|
||||
}
|
||||
|
||||
private void AppendDefaultValues(Dictionary<string, object> defaults)
|
||||
|
|
@ -118,11 +121,22 @@ namespace Guru
|
|||
private void FetchAllConfigs(bool immediately = false)
|
||||
{
|
||||
var span = TimeSpan.FromHours(_fetchIntervalHours);
|
||||
if(_isDebug || immediately) span = TimeSpan.Zero;
|
||||
bool success = true;
|
||||
|
||||
// if (_isDebug || immediately)
|
||||
// {
|
||||
// FetchAllConfigsImmediately();
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (_isDebug || immediately)
|
||||
{
|
||||
span = TimeSpan.Zero;
|
||||
}
|
||||
|
||||
_firebaseRemote.FetchAsync(span)
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
bool success = true;
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
|
|
@ -130,11 +144,98 @@ namespace Guru
|
|||
success = false;
|
||||
}
|
||||
|
||||
if (success) OnFetchDataCompleted();
|
||||
|
||||
if (success)
|
||||
{
|
||||
_firebaseRemote.ActivateAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
success = false;
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
LogE($" --- Active AllConfigs fails: {res}");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
LogI($"[REMOTE] --- ActiveAsync success: {success}");
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 立即拉取所有的配置
|
||||
/// </summary>
|
||||
private void FetchAllConfigsImmediately()
|
||||
{
|
||||
bool success = true;
|
||||
_firebaseRemote.FetchAndActivateAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
success = false;
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
LogE($" --- Fetch AllConfigs fails: {res}");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
LogI($"{Tag} --- FetchAndActivateAsync success");
|
||||
}
|
||||
LogI($"{Tag} --- FetchAndActivateAsync success: {success}");
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值更新回调
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="updateEvent"></param>
|
||||
private void OnConfigUpdatedHandler(object sender, ConfigUpdateEventArgs updateEvent)
|
||||
{
|
||||
if (updateEvent.Error != RemoteConfigError.None)
|
||||
{
|
||||
Debug.LogError($"{Tag} --- RemoteConfigError: {updateEvent.Error}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_firebaseRemote.ActivateAsync().ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsCompleted)
|
||||
{
|
||||
if (updateEvent.UpdatedKeys != null)
|
||||
{
|
||||
var updateKeys = updateEvent.UpdatedKeys.ToArray();
|
||||
string key = "";
|
||||
int i = 0;
|
||||
int count = updateEvent.UpdatedKeys.Count();
|
||||
while (i < count)
|
||||
{
|
||||
key = updateEvent.UpdatedKeys.ElementAt(i);
|
||||
if (_changeEvents.TryGetValue(updateKeys[i], out var callback))
|
||||
{
|
||||
callback?.Invoke(key, _firebaseRemote.GetValue(key).StringValue);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "com.guru.unity.sdk.core",
|
||||
"displayName": "Guru SDK Core",
|
||||
"version": "2.3.1",
|
||||
"version": "1.1.0",
|
||||
"description": "Guru SDK core for Unity developers",
|
||||
"unity": "2021.3",
|
||||
"author":{
|
||||
|
|
@ -14,6 +14,6 @@
|
|||
"com.unity.editorcoroutines": "1.0.0",
|
||||
"com.unity.mobile.notifications": "2.2.2",
|
||||
"com.unity.mobile.android-logcat": "1.3.2",
|
||||
"com.unity.purchasing": "4.10.0"
|
||||
"com.unity.purchasing": "4.12.2"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue