Android Google Analytics不会报告未捕获的崩溃和异常

时间:2014-09-17 12:43:49

标签: android google-analytics google-analytics-v4 uncaughtexceptionhandler

我正在创建一个应用程序,我希望在其中查看Google Analytics(分析)帐户中的崩溃和异常报告。

我正在使用以下代码来实现此功能:

“analytics_global_config.xml”

<?xml version="1.0" encoding="utf-8"?>
  <resources>
  <string name="ga_appName">app_name</string>
  <string name="ga_logLevel">verbose</string>
  <integer name="ga_dispatchPeriod">1</integer>
  <bool name="ga_dryRun">true</bool>
</resources>

我已在清单文件中声明了这个xml,如下所示:

<meta-data
    android:name="com.google.android.gms.analytics.globalConfigResource"
    android:resource="@xml/analytic_global_config" />

跟踪的xml文件:“analytics_track.xml”如下:

<?xml version="1.0" encoding="utf-8"?>
 <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
    <string name="ga_trackingId">UA-XXXXXXXX-1
     </string>
    <bool name="ga_autoActivityTracking">true
     </bool>
    <bool name="ga_reportUncaughtExceptions">true
     </bool>
    <string name="ga_sampleFrequency">99.8</string>
    <integer name="ga_sessionTimeout">2000</integer>
    <bool name="ga_anonymizeIp">true</bool>

在应用程序类中,我使用了以下代码:

Tracker tracker = GoogleAnalytics.getInstance(this).(R.xml.analytics_track);

我正在以应用程序开始登录:

09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: Loading Tracker config values.
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] trackingId loaded: UA- 54498004-1
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] sample frequency loaded: 99.8
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] session timeout loaded: 2000000
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] auto activity tracking loaded: true
09-23 16:26:57.775: V/GAV4(7763): Thread[client_id_fetcher,5,main]: Loaded client id from disk.
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] anonymize ip loaded: true
09-23 16:26:57.775: V/GAV4(7763): Thread[main,5,main]: [Tracker] anonymize ip loaded: false
09-23 16:26:57.785: V/GAV4(7763): Thread[main,5,main]: ExceptionReporter created, original handler is com.android.internal.os.RuntimeInit$UncaughtHandler
09-23 16:26:57.785: V/GAV4(7763): Thread[main,5,main]: Uncaught exceptions will be reported to Google Analytics.
09-23 16:27:02.895: V/GAV4(7763): Thread[GAThread,5,main]: connecting to Analytics service
09-23 16:27:02.985: V/GAV4(7763): Thread[main,5,main]: service connected, binder: android.os.BinderProxy@41ae4840
09-23 16:27:02.985: V/GAV4(7763): Thread[main,5,main]: bound to service
09-23 16:27:03.015: V/GAV4(7763): Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
09-23 16:27:03.055: V/GAV4(7763): Thread[main,5,main]: Connected to service
09-23 16:27:03.445: I/GAV4(7763): Thread[GAThread,5,main]: No campaign data found.
09-23 16:27:03.445: V/GAV4(7763): Thread[GAThread,5,main]: Initialized GA Thread

- 一段时间后“

09-23 16:32:04.910: V/GAV4(7763): Thread[disconnect check,5,main]: Disconnecting due to     inactivity
09-23 16:32:04.920: V/GAV4(7763): Thread[disconnect check,5,main]: Disconnected from service

问题是它没有给出未捕获的崩溃和异常。我手动制作了eception,在异常之后,我得到以下日志:

09-23 16:32:22.770: V/GAV4(7763): Thread[main,5,main]: Tracking Exception: ActivityNotFoundException (@FullVideoActivity:onCompletion:276) {main}
09-23 16:32:22.770: V/GAV4(7763): Thread[main,5,main]: Dispatch call queued. Dispatch will run once initialization is complete.
09-23 16:32:22.770: V/GAV4(7763): Thread[main,5,main]: Passing exception to original handler.

我没有在Google Analytics(分析)帐户上遇到任何异常和崩溃。 任何人都可以帮我解决这个问题吗?

由于 Ishan jain

1 个答案:

答案 0 :(得分:0)

您没有将点击发送到服务。你应该得到Thread [GAThread,5,main]:初始化的GA线程如下:

    Thread[GAThread,5,main]: Loaded clientId
    Thread[GAThread,5,main]: putHit called
    Thread[GAThread,5,main]: Sending hit to service ..

在应用程序类中,您必须使用:

 Tracker tracker = GoogleAnalytics.getInstance(this).newTracker(R.xml.analytics_track);

如果它仍无法正常工作,您还可以尝试通过在应用程序类的onCreate()中添加以下方法来设置GoogleAnalytics:

private void initGoogleAnalytics() {
    GoogleAnalytics mGoogleAnalytics = GoogleAnalytics.getInstance(this);
    mGoogleAnalytics.setDryRun(false);
    mGoogleAnalytics.setLocalDispatchPeriod(10);
    mGoogleAnalytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
    mGoogleAnalytics.enableAutoActivityReports(this);
}