analytics v4 uncaught exceptions not working

2019-01-26 21:18发布

问题:

My app_tracker.xml

<string name="ga_trackingId">UA-XXXX....</string>
<string name="ga_logLevel">verbose</string>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>

My setup code in Activity

private void setupGoogleAnalytics() {
   MyApp app= (MyApp) getApplication();
   Tracker myTracker=app.getTracker(MyApp.TrackerName.APP_TRACKER);
   myTracker.enableAutoActivityTracking(true);
   GoogleAnalytics.getInstance(this).enableAutoActivityReports(app);
}

My App

public class MyApp extends Application {
    public enum TrackerName {
        APP_TRACKER // Tracker used only in this app.
    }    
    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
    public MyApp() {
        super();
    }
    public synchronized Tracker getTracker(TrackerName trackerId) {
        if (!mTrackers.containsKey(trackerId)) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t=analytics.newTracker(R.xml.app_tracker);
            mTrackers.put(trackerId, t);
        }
        return mTrackers.get(trackerId);
    }
}

I can send screens and events. But I am just not able to send uncaughtexceptions to Google Analytics by simulating a NPE. It was working pre V4. What am I missing here ?

回答1:

do you have this in your manifest:

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


回答2:

I had the same problem and i solved it by adding this line myTracker.enableExceptionReporting(true); to the set up method

private void setupGoogleAnalytics() {
  MyApp app= (MyApp) getApplication();
  Tracker myTracker=app.getTracker(MyApp.TrackerName.APP_TRACKER);
  myTracker.enableAutoActivityTracking(true);
  myTracker.enableExceptionReporting(true); //add this line
  GoogleAnalytics.getInstance(this).enableAutoActivityReports(app);
}


回答3:

I think that the fact that it is a bug has to be an answer since project member has acknowledged it as a bug and working on a fix https://code.google.com/p/analytics-issues/issues/detail?id=443