Android Google Analytics - Connection to service failed

后端 未结 4 670
臣服心动
臣服心动 2020-12-29 18:53

Just started implementing Google Analytics V2 in my Android application, though I\'m having troubles.

I believe I\'ve set up an acount with a property and profiles c

相关标签:
4条回答
  • 2020-12-29 19:26

    Just an addition that might save you hours to debug. I did not see local debug messages of gav2 in logcat. I would only see four gav2 startup messages like "need to call initialize.." and "Service Unavailable". Though i did see views in Google Analytics Real-Time reports.

    What happened: i started with the following line in onStart()

    EasyTracker.getInstance().activityStart(this); 
    

    And than turned debugging on from onCreate();

    GoogleAnalytics.getInstance(getApplicationContext()).setDebug(true);
    

    This is obviously wrong as onCreate() is executed before onStart(). Now i have both set sequentially from onStart().

    EasyTracker.getInstance().activityStart(this); 
    GoogleAnalytics.getInstance(getApplicationContext()).setDebug(true);
    

    What went wrong?

    I followed the Google example for GAV2 Beta 4 (https://developers.google.com/analytics/devguides/collection/android/v2/advanced). It starts out the to onStart() code:

    EasyTracker.getInstance().activityStart(this); 
    

    Than to enable debugging and adding event tracking, i followed the Advanced examples. Without really thinking i added to onCreate (just like the example):

    googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext())
    

    I used googleAnalytics to enable debugging and events. As it does not throw exceptions and it actually produces results in Google Analytics, i just did not notice the mistake for some time. Ofcourse the gav2 startup logcat message indicates that something is wrong. But if you are not familiar with gav2 this might as well be 'normal' behaviour.

    As more people might follow the same example and learning curve, i thought i might take a moment and write it down, hope it saved you some time. If you don't see messages like "putHit called" in logcat, you might have a similar problem. Good luck.

    0 讨论(0)
  • 2020-12-29 19:33

    I can now see results in my analytics page so apparently I just needed to wait.

    Google should do something about that warning, it can be misleading.

    Update: An interesting thing I've noticed which may also help, Google Analytics web interface doesn't show data from the current day on default. In order to view the data collected from the current day, you need to click on the date range picker on the top-right side, and select the current day from the Calendar (or Today from the combobox).

    0 讨论(0)
  • 2020-12-29 19:36

    In your mainActivity onCreate() just add the following lines:

    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
    googleAnalytics.setAppOptOut(false); 
    
    0 讨论(0)
  • 2020-12-29 19:37

    One more thing about it - dont be surprised if you wont see your tracks in Real-Time report - ga_dispatchPeriod is set to 30 mins by default

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