Dispatching

This document describes how you can manage dispatching data to Google Analytics using the Google Analytics SDK v4 for Android.

Overview

Data collected using the Google Analytics SDK v4 for Android is stored locally before being dispatched on a separate thread to Google Analytics.

Data must be dispatched and received by 4 a.m. of the following day, in the local timezone of each view. Any data received later than that will not appear in reports. For example, if a hit is queued locally at 11:59pm, it must be dispatched within 4 hours, by 3:59am, to appear in reports. On the other hand, a hit queued at 12:00am must be dispatched within 28 hours, i.e. 3:59am of the following day, in order to appear in reports.

Periodic dispatching

By default, data is dispatched from the Google Analytics SDK v4 for Android every 30 minutes.

To set the dispatch period programmatically:

// Set the dispatch period to 90 seconds.
GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(90);

To set the dispatch period in the XML configuration file:

<integer name="ga_dispatchPeriod">30</integer>

Setting a zero or negative value will disable periodic dispatch, requiring that you use manual dispatch if you want to send any data to Google Analytics.

// Disable periodic dispatch by setting dispatch period to a value less than 1.
GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(0);

If a user loses network access or quits your app while there are still hits waiting to be dispatched, those hits are persisted in local storage. They will be dispatched the next time your app is running and dispatch is called.

Manual dispatching

To manually dispatch hits, for example when you know the device radio is already being used to send other data:

GoogleAnalytics.getInstance(this).dispatchLocalHits();

Background dispatching

To enable background dispatching on apps running on non-Google Play devices, in the configuration file ApplicationManifest.xml:

  • Get the WAKE_LOCK permission.
  • Register AnalyticsReceiver.
  • Register AnalyticsService.

For example:

<manifest>
  <!-- ... -->

  <!-- Get permission for reliable local dispatching on non-Google Play devices. -->
  <uses-permission android:name="android.permission.WAKE_LOCK" />

  <application name="com.example.MyApp">
    <!-- Register AnalyticsReceiver and AnalyticsService to support background
         dispatching on non-Google Play devices. -->
    <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
      android:enabled="true">
      <intent-filter>
        <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
      </intent-filter>
    </receiver>
    <service android:name="com.google.android.gms.analytics.AnalyticsService"
      android:enabled="true"
      android:exported="false"/>

    <!-- ... -->
  </application>
</manifest>