update: 升级自打点版本至 1.10.4
parent
8f3aa1437d
commit
19c9cb831b
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 4438c644309264b1babdb7f1fd0431b6
|
guid: 07cf2335bd298401b8015718fca55265
|
||||||
PluginImporter:
|
PluginImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 93255faba714a477da458107e107b535
|
guid: b0e58ca75957d470cbc4951b34f31bf8
|
||||||
PluginImporter:
|
PluginImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
Binary file not shown.
|
|
@ -7,13 +7,13 @@ namespace Guru
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
public class GuruAnalytics
|
public class GuruAnalytics
|
||||||
{
|
{
|
||||||
// Plugin Version
|
// Plugin Version
|
||||||
public const string Version = "1.10.1";
|
public const string Version = "1.10.4";
|
||||||
|
|
||||||
public static readonly string Tag = "[ANA]";
|
public static readonly string Tag = "[ANA]";
|
||||||
private static readonly string ActionName = "logger_error";
|
private static readonly string ActionName = "logger_error";
|
||||||
|
|
@ -70,6 +70,11 @@ namespace Guru
|
||||||
if (Agent != null) Agent.EnableErrorLog = _enableErrorLog;
|
if (Agent != null) Agent.EnableErrorLog = _enableErrorLog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 错误 code 表
|
||||||
|
/// </summary>
|
||||||
|
public static List<int> ErrorCodeList = new List<int>();
|
||||||
|
|
||||||
#region 公用接口
|
#region 公用接口
|
||||||
|
|
||||||
|
|
@ -336,77 +341,11 @@ namespace Guru
|
||||||
/// 获取SDK回调
|
/// 获取SDK回调
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
private static void OnSDKCallback(string msg)
|
private static void OnSDKCallback(string raw)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(msg)) return;
|
if (string.IsNullOrEmpty(raw)) return;
|
||||||
|
if (!raw.Contains($"\"{ActionName}\"")) return; // 不对其他行为的日志进行过滤
|
||||||
//------- message send to unity ----------
|
ParseWithJson(raw);
|
||||||
Debug.Log($"{Tag} get callback errorInfo:\n{msg}");
|
|
||||||
|
|
||||||
string patten = "";
|
|
||||||
string patten2 = "";
|
|
||||||
int idx = 0;
|
|
||||||
int idx2 = 0;
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
int code = (int)AnalyticsCode.Unknown;
|
|
||||||
string info = msg;
|
|
||||||
|
|
||||||
if (msg.Contains("msg\":"))
|
|
||||||
{
|
|
||||||
var arr = msg.Split(new string[] {"msg\":"}, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (arr.Length > 1)
|
|
||||||
{
|
|
||||||
info = arr[1];
|
|
||||||
if (info.StartsWith("\"")) info = info.Substring(1);
|
|
||||||
if (info.EndsWith("\"}}")) info = info.Replace("\"}}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
patten = "action\":\"";
|
|
||||||
if (msg.Contains(patten))
|
|
||||||
{
|
|
||||||
idx = msg.IndexOf(patten, StringComparison.Ordinal) + patten.Length;
|
|
||||||
string act = msg.Substring(idx, ActionName.Length);
|
|
||||||
if (act == ActionName)
|
|
||||||
{
|
|
||||||
patten = "code\":";
|
|
||||||
patten2 = ",\"msg";
|
|
||||||
idx = msg.IndexOf(patten);
|
|
||||||
idx2 = msg.IndexOf(patten2);
|
|
||||||
|
|
||||||
len = idx2 - (idx + patten.Length);
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
string c = msg.Substring(idx + patten.Length, len);
|
|
||||||
int.TryParse(c, out code);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Catch target code to report errors
|
|
||||||
switch ((AnalyticsCode)code)
|
|
||||||
{
|
|
||||||
case AnalyticsCode.Network_Lost:
|
|
||||||
case AnalyticsCode.ERROR_API:
|
|
||||||
case AnalyticsCode.ERROR_RESPONSE:
|
|
||||||
case AnalyticsCode.ERROR_CACHE_CONTROL:
|
|
||||||
case AnalyticsCode.ERROR_DELETE_EXPIRED:
|
|
||||||
case AnalyticsCode.ERROR_LOAD_MARK:
|
|
||||||
case AnalyticsCode.ERROR_DNS:
|
|
||||||
case AnalyticsCode.ERROR_ZIP:
|
|
||||||
OnLoggerErrorEvent(code, info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.LogError($"{Tag} Catch ex: {ex}\tJson:{msg}");
|
|
||||||
Analytics.LogCrashlytics($"{Tag} --- Json:{msg} Ex:{ex}");
|
|
||||||
OnLoggerErrorEvent(code, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -416,12 +355,15 @@ namespace Guru
|
||||||
/// <param name="errorInfo"></param>
|
/// <param name="errorInfo"></param>
|
||||||
private static void OnLoggerErrorEvent(int code, string errorInfo = "")
|
private static void OnLoggerErrorEvent(int code, string errorInfo = "")
|
||||||
{
|
{
|
||||||
Debug.Log($"{Tag} --- OnLoggerErrorEvent: code:{code}\tinfo:{errorInfo}");
|
// Debug.Log($"{Tag} --- OnLoggerErrorEvent: code:{code}\tinfo:{errorInfo}");
|
||||||
|
|
||||||
|
var codeString = ((AnalyticsCode)code).ToString();
|
||||||
|
if (string.IsNullOrEmpty(codeString) || codeString == "Unknown") codeString = $"ErrorCode:{code}";
|
||||||
|
|
||||||
Dictionary<string, dynamic> parameters = new Dictionary<string, dynamic>()
|
Dictionary<string, dynamic> parameters = new Dictionary<string, dynamic>()
|
||||||
{
|
{
|
||||||
{"item_category", "error_event"},
|
{"item_category", "error_event"},
|
||||||
{"item_name", ((AnalyticsCode)code).ToString()},
|
{"item_name", codeString},
|
||||||
{"country", IPMConfig.IPM_COUNTRY_CODE},
|
{"country", IPMConfig.IPM_COUNTRY_CODE},
|
||||||
{"network", Application.internetReachability.ToString()},
|
{"network", Application.internetReachability.ToString()},
|
||||||
};
|
};
|
||||||
|
|
@ -438,14 +380,220 @@ namespace Guru
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters["err"] = errorInfo;
|
parameters["err"] = errorInfo;
|
||||||
Debug.Log($"{Tag} ------------ ErrorLogInfo:: code:{code}\tinfo:{errorInfo}");
|
|
||||||
|
Debug.Log($"{Tag} ------ ErrorLogInfo:: code:{codeString}\tinfo:{errorInfo}");
|
||||||
|
|
||||||
|
#if !UNITY_EDITOR
|
||||||
// Only for firebase GA
|
// Only for firebase GA
|
||||||
Analytics.LogEvent("dev_audit", parameters,
|
Analytics.LogEvent("dev_audit", parameters,
|
||||||
new Analytics.EventSetting() { EnableFirebaseAnalytics = true });
|
new Analytics.EventSetting() { EnableFirebaseAnalytics = true });
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static bool ParseWithJson(string json)
|
||||||
|
{
|
||||||
|
Debug.Log($"{Tag} ------ ParseWithJson: json:\n{json}");
|
||||||
|
|
||||||
|
int code = (int)AnalyticsCode.Unknown;
|
||||||
|
string info = json;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dict = JsonConvert.DeserializeObject<JObject>(json);
|
||||||
|
if(dict != null && dict.TryGetValue("data", out var jData))
|
||||||
|
{
|
||||||
|
var j = jData.Value<JObject>();
|
||||||
|
if (j != null && j.TryGetValue("code", out var jCode))
|
||||||
|
{
|
||||||
|
code = jCode.Value<int>();
|
||||||
|
|
||||||
|
if (j.TryGetValue("msg", out var jMsg))
|
||||||
|
{
|
||||||
|
info = jMsg.Value<string>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = $"wrong msg format: {json}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = "no data property";
|
||||||
|
}
|
||||||
|
ReportCodeInfo(code, info);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string p = "\"msg\":\"";
|
||||||
|
string m = json;
|
||||||
|
if (json.Contains(p)) m = json.Substring(json.IndexOf(p) + p.Length);
|
||||||
|
info = $"JsonEX:{m}";
|
||||||
|
// Debug.Log($"{Tag} --- {info}");
|
||||||
|
Analytics.LogCrashlytics(json, false);
|
||||||
|
Analytics.LogCrashlytics(info);
|
||||||
|
ReportCodeInfo(code, info);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ParseWithRaw(string raw)
|
||||||
|
{
|
||||||
|
int code = (int)AnalyticsCode.Unknown;
|
||||||
|
string info = raw;
|
||||||
|
|
||||||
|
//------- 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\":\"";
|
||||||
|
if (raw.Contains(patten))
|
||||||
|
{
|
||||||
|
|
||||||
|
info = raw.Substring(raw.IndexOf(patten, StringComparison.Ordinal) + patten.Length);
|
||||||
|
if (!string.IsNullOrEmpty(info))
|
||||||
|
{
|
||||||
|
if (info.StartsWith("\"")) info = info.Substring(1, info.Length - 1);
|
||||||
|
if (info.EndsWith("\"}}")) info = info.Replace("\"}}", "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = "msg is null";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = "no msg property";
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
len = idx2 - (idx + patten.Length);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
string c = raw.Substring(idx + patten.Length, len);
|
||||||
|
int.TryParse(c, out code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catch target code to report errors
|
||||||
|
switch ((AnalyticsCode)code)
|
||||||
|
{
|
||||||
|
case AnalyticsCode.Network_Lost:
|
||||||
|
case AnalyticsCode.ERROR_API:
|
||||||
|
case AnalyticsCode.ERROR_RESPONSE:
|
||||||
|
case AnalyticsCode.ERROR_CACHE_CONTROL:
|
||||||
|
case AnalyticsCode.ERROR_DELETE_EXPIRED:
|
||||||
|
case AnalyticsCode.ERROR_LOAD_MARK:
|
||||||
|
case AnalyticsCode.ERROR_DNS:
|
||||||
|
case AnalyticsCode.ERROR_ZIP:
|
||||||
|
OnLoggerErrorEvent(code, info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogError($"{Tag} Catch ex: {ex}\tJson:{raw}");
|
||||||
|
Analytics.LogCrashlytics(raw, false);
|
||||||
|
Analytics.LogCrashlytics($"{Tag} --- Json:{raw} Ex:{ex}");
|
||||||
|
OnLoggerErrorEvent(code, info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raw.Contains("msg"))
|
||||||
|
{
|
||||||
|
Analytics.LogCrashlytics(raw, false);
|
||||||
|
Analytics.LogCrashlytics($"{Tag} --- format error:{raw}");
|
||||||
|
OnLoggerErrorEvent(code, raw.Substring(raw.IndexOf("msg\":" ) + 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report error to api
|
||||||
|
private static void ReportCodeInfo(int code, string info)
|
||||||
|
{
|
||||||
|
var ac = (AnalyticsCode)code;
|
||||||
|
|
||||||
|
Debug.Log($"{Tag} ------ ReportCodeInfo: code:{code}[{ac}] \tinfo:{info}");
|
||||||
|
bool canCatch = false;
|
||||||
|
switch (ac)
|
||||||
|
{
|
||||||
|
case AnalyticsCode.Unknown:
|
||||||
|
case AnalyticsCode.DELETE_EXPIRED:
|
||||||
|
case AnalyticsCode.UPLOAD_FAIL:
|
||||||
|
case AnalyticsCode.Network_Lost:
|
||||||
|
case AnalyticsCode.CRONET_INIT_FAIL:
|
||||||
|
case AnalyticsCode.CRONET_INIT_EXCEPTION:
|
||||||
|
case AnalyticsCode.ERROR_API:
|
||||||
|
case AnalyticsCode.ERROR_RESPONSE:
|
||||||
|
case AnalyticsCode.ERROR_CACHE_CONTROL:
|
||||||
|
case AnalyticsCode.ERROR_DELETE_EXPIRED:
|
||||||
|
case AnalyticsCode.ERROR_LOAD_MARK:
|
||||||
|
case AnalyticsCode.ERROR_DNS:
|
||||||
|
case AnalyticsCode.ERROR_ZIP:
|
||||||
|
case AnalyticsCode.ERROR_DNS_CACHE:
|
||||||
|
case AnalyticsCode.CRONET_INTERCEPTOR:
|
||||||
|
canCatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code > 100 && code <= 200)
|
||||||
|
{
|
||||||
|
// 100 < code <= 200
|
||||||
|
canCatch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ErrorCodeList != null && ErrorCodeList.Count > 0)
|
||||||
|
{
|
||||||
|
if (ErrorCodeList[0] == -1)
|
||||||
|
{
|
||||||
|
canCatch = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
canCatch = ErrorCodeList.Contains(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canCatch) OnLoggerErrorEvent(code, info);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region UNIT_TEST
|
||||||
|
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
|
public static void TestOnCallback(string msg)
|
||||||
|
{
|
||||||
|
OnSDKCallback(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -455,7 +603,11 @@ namespace Guru
|
||||||
{
|
{
|
||||||
Unknown = -1,
|
Unknown = -1,
|
||||||
|
|
||||||
|
DELETE_EXPIRED = 12,
|
||||||
|
UPLOAD_FAIL = 14,
|
||||||
Network_Lost = 22,
|
Network_Lost = 22,
|
||||||
|
CRONET_INIT_FAIL = 26,
|
||||||
|
CRONET_INIT_EXCEPTION = 27,
|
||||||
|
|
||||||
ERROR_API = 101,
|
ERROR_API = 101,
|
||||||
ERROR_RESPONSE = 102,
|
ERROR_RESPONSE = 102,
|
||||||
|
|
@ -464,6 +616,8 @@ namespace Guru
|
||||||
ERROR_LOAD_MARK = 105,
|
ERROR_LOAD_MARK = 105,
|
||||||
ERROR_DNS = 106,
|
ERROR_DNS = 106,
|
||||||
ERROR_ZIP = 107,
|
ERROR_ZIP = 107,
|
||||||
|
ERROR_DNS_CACHE = 108,
|
||||||
|
CRONET_INTERCEPTOR = 109,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue