android-Google Analytics(分析)两次发送未捕获的异常
作者:互联网
为了将未捕获的异常的堆栈跟踪信息包含到Google Analytics(分析)中,我将默认的ExceptionParser替换为自定义的ExceptionParser.
现在,我获得了带有stackstrace的异常的另一个报表,该报表具有不带stacktrace的异常(默认值).我究竟做错了什么?
public class AnalyticsHelper
{
/**
* This method is called in my Application#onCreate(..)
**/
public static void initAnalytics(Context c)
{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(c);
analytics.setAppOptOut(PreferenceManager.getDefaultSharedPreferences(c).getBoolean(PreferencesActivity.KEY_ANAYLTICS_OPT_OUT, false));
// setting uncaught exception handler
ExceptionReporter reporter = new ExceptionReporter(analytics.getInstance(c).newTracker(R.xml.tracker), Thread.getDefaultUncaughtExceptionHandler(), c);
reporter.setExceptionParser(new ExceptionParser()
{
@Override
public String getDescription(String p_thread, Throwable throwable)
{
StringWriter trace = new StringWriter();
throwable.printStackTrace(new PrintWriter(trace));
String stacktrace = trace.toString();
String message = (throwable.getMessage() == null) ? "no message" : throwable.getMessage();
return "Message: " + message
+ ", Stacktrace: " + stacktrace;
}
});
Thread.setDefaultUncaughtExceptionHandler(reporter);
}
}
tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<integer name="ga_sessionTimeout">300</integer>
<bool name="ga_reportUncaughtExceptions">true</bool>
<bool name="ga_autoActivityTracking">false</bool>
<integer name="ga_dispatchPeriod">5</integer>
<string name="ga_trackingId">XXXXXX</string>
</resources>
解决方法:
To automatically send all uncaught exceptions in your app using EasyTracker, add this line to your analytics.xml file:
<bool name="ga_reportUncaughtExceptions">true</bool>
After sending an exception using automatic exception measurement, EasyTracker will pass the exception on to the Thread’s default exception handler.
通过将ga_reportUncaughtExceptions设置为true,跟踪程序将自动发送异常,因此您获得了一份额外的报告,而没有stacktrace.删除它,您将只获得一份报告.
标签:exception,google-analytics,android 来源: https://codeday.me/bug/20191121/2054219.html