android google analytics v3: “Service unavailable”

2019-04-18 04:39发布

问题:

following the simple guide here, https://developers.google.com/analytics/devguides/collection/android/v3/

when i run my app, i get this,

10-28 18:01:17.973  27022-27069/com.foo.bar W/GAV3﹕ Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
10-28 18:01:17.973  27022-27069/com.foo.bar I/GAV3﹕ Thread[GAThread,5,main]: No campaign data found.
10-28 18:01:17.973      525-865/system_process W/ActivityManager﹕ Unable to start service Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) } U=0: not found

from the debug, it's trying to start a service that doesn't exist. it seems like i should have to define that in my manifest, but the guide says nothing about that.

i've placed analytics.xml in my res/values folder as such,

<?xml version="1.0" encoding="utf-8" ?>
<resources
    xmlns:tools="https://schemas.android.com/tools"
    tools:ignore="TypographyDashes">

  <string name="ga_trackingId">UA-XXX-1</string>
  <bool name="ga_autoActivityTracking">true</bool>
  <bool name="ga_reportUncaughtExceptions">true</bool>
  <integer name="ga_dispatchPeriod">1</integer>
  <bool name="ga_debug">true</bool>
</resources>

i'm completely stumped here since the guide is so simple. if it makes any difference (and it shouldn't), i'm building with android studio / gradle, and adding the dependency like this,

compile files('libs/libGoogleAnalyticsServices.jar')

EDIT: had a thought ... this device DOES NOT run google services. does the google analytics lib depend on the google service APK being installed?

回答1:

You can ignore that warning for now.

From the Google Mobile App Analytics group:

The SDK is simply attempting to connect to a global dispatch service, which is unavailable on your device.  The hits are still being generated and sent to GA normally.

The GA developer site will provide more information on this soon.

Link to the group: https://groups.google.com/forum/#!forum/ga-mobile-app-analytics



回答2:

If you are using analytics V3 you should remove

    <bool name="ga_debug">true</bool>

as ga_debug is for v2

refer:Google Analytics SDK for Android - EasyTracker Parameters



回答3:

Same problem here, you might have just forgotten to initialize your tracker.

Under "next steps" on the GA3 site, it states "Before any data can be measured, you must initialize at least one tracker via GoogleAnalytics singleton by providing a Context and a Google Analytics property ID:"

Just insert this code into your main activities' onCreate method:

// Initialize a tracker using a Google Analytics property ID.
GoogleAnalytics.getInstance(this).getTracker("UA-XXXX-Y")

You'd think they'd mention this on their main page, but I guess they just kind of expect you'll be curious about the advanced settings.



回答4:

I think you can use the

GAServiceManager.getInstance().setLocalDispatchPeriod(10);

after this line it seems to work just fine and send the events