Android Google Analytics – Connection to service failed

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 correctly.
I’ve supplied my key in the analytics.xml file and in each activity I use the

  • using getWindowManager() inside BroadcastReceiver
  • Support for multiple active overlapping surface views in Android
  • Is there any difference between Apache's Base64.encodeBase64 and Android's Base64.encode with Base64.Default flag?
  • See changes in Android Support Library sources between two versions
  • onConfigurationChanged not getting called
  • How to manually install java libs and keep /tmp as noexec?
  • EasyTracker.getInstance().activityStart(this); in the onStart method

    and

    EasyTracker.getInstance().activityStop(this); in the onStop method of every activity.

    However I don’t seem to see any results on the Google Analytics website. Moreover, I turned on the debug options and I can see in log cat various messages from Gav2 (Google Analytics), implying on a problem.

    For example

    11-04 21:56:48.000: W/GAV2(6376): Thread[main,5,main]: **Connection to service failed 1**
    11-04 21:56:48.040: W/GAV2(6376): Thread[main,5,main]: **Need to call initialize() and be in fallback mode to start dispatch.**
    11-04 21:56:48.050: I/GAV2(6376): Thread[main,5,main]: ExceptionReporter created, original handler is com.keypod.utils.AppCrashExceptionHandler
    11-04 21:56:50.055: I/GAV2(6376): Thread[GAThread,5,main]: No campaign data found.
    11-04 21:56:50.060: I/GAV2(6376): Thread[GAThread,5,main]: putHit called
    11-04 21:56:50.410: I/GAV2(6376): Thread[GAThread,5,main]: putHit called
    11-04 21:56:53.035: I/GAV2(6376): Thread[Service Reconnect,5,main]: connecting to Analytics service
    11-04 21:56:53.035: I/GAV2(6376): Thread[Service Reconnect,5,main]: connect: bindService returned false for Intent { act=com.google.android.gms.analytics.service.START (has extras) }
    **11-04 21:56:53.035: W/GAV2(6376): Thread[Service Reconnect,5,main]: Connection to service failed 1
    11-04 21:56:53.035: I/GAV2(6376): Thread[Service Reconnect,5,main]: falling back to local store**
    11-04 21:56:53.040: I/GAV2(6376): Thread[GAThread,5,main]: Sending hit to store
    11-04 21:56:53.100: I/GAV2(6376): Thread[GAThread,5,main]: Sending hit to store
    11-04 21:56:53.150: V/GAV2(6376): Thread[GAThread,5,main]: dispatch running...
    

    It seems like it can’t connect and then it “fallsback” to local store.
    Am I doing something wrong? Or should I just ignore that warning and wait for the results to show up on the site?

    I followed Google’s guide step-by-step.

    Thanks!

    Related posts:

    How to determine if Android Application is started with JUnit testing instrumentation?
    android untrue resource not found exception
    Unable to set parent activity for new activities in Android Studio. Error: Hierarchical parent must ...
    Is there anyway to make an EditText start typing at the top left corner of the EditText?
    How to use TextInputLayout in new android design library
    When are ALL the cases when the onSaveInstanceState() method called?
  • ViewGroup{TextView,…}.getMeasuredHeight gives wrong value is smaller than real height
  • EditText focus inconsistent across layouts
  • Build android with gradle, replace string each product flavor
  • How to iterate through SparseArray?
  • Android ExoPlayer onProgressChanged
  • What's the difference between clear cache & clear data in Android settings
  • 4 Solutions collect form web for “Android Google Analytics – Connection to service failed”

    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).

    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

    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.

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

    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
    googleAnalytics.setAppOptOut(false); 
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.