GoogleAnalytics.getInstance(this) not respond

前端 未结 1 710
无人及你
无人及你 2020-12-11 19:49

I have an android applcation and I added Google Analytics Tracker to it and it works (I can see the views in the Analytics panel).

The problem is that sometime the a

1条回答
  •  囚心锁ツ
    2020-12-11 20:14

    This is a known issue with Google Play Services 6.5. See Android GoogleAnalytics getInstance for details.

    The issue is fixed in Google Play Services 7.0 that was releases on 2015, March 19th. http://developer.android.com/google/play-services/index.html

    If you must use Play Services 6.5, the workaround is to either configure Google Analytics from code instead of xml or downgrade to Google Play Services 6.1.

    The following code when added to your Application class is equivalent to your manifest configuration:

    public class MyApplication extends Application  {
      //...
      private Tracker mTracker;
      public synchronized Tracker getAppTracker() {
        if (mTracker == null) {
          GoogleAnalytics analytics = GoogleAnalytics.getInstance(this)
          mTracker = analytics.newTracker("XX-XXXXXXXX-X"); // Replace with your real tracker id
          mTracker.enableAutoActivityTracking(true);
          mTracker.enableExceptionReporting(true);
          mTracker.setSessionTimeout(-1);
    
          // mTracker.setSampleRate(100.0d); // Not needed. The default sampling rate it 100%
        }
        return mTracker; 
      }
    }
    

    0 讨论(0)
提交回复
热议问题