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