Important: This document describes a legacy version of the SDK. New users should use the latest SDK.

Dispatching - iOS SDK

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

Overview

In the Google Analytics SDK for iOS, collected data like screen views or events are stored locally in a queue before being sent to the Google Analytics servers. The process by which these pieces of data (referred to here as "hits") are sent from the SDK to Google Analytics is known as dispatching.

Dispatching is unique to the mobile collections libraries and is designed to mitigate the challenges of unreliable network access and limited battery life.

There are two types of dispatching:

  • Periodic dispatch – automatically dispatches hits at a recurring interval that you specify.
  • Manual dispatch – manually dispatch hits to send data when it is convenient for you, for example when there is an existing HTTP connection.

The remainder of this document will provide a more in-depth look at each type of dispatch and how to implement them in your app.

Periodic Dispatch

As your app collects GA data, that data is added to a queue and periodically dispatched to Google Analytics. Periodic dispatch can occur either when your app is running in the foreground or the background.

The default dispatch period is 2 minutes. You can provide your own interval in seconds by calling setDispatchPeriod:(NSTimeInterval) as in this example:

[[GAI sharedInstance] setDispatchPeriod:60];

Setting a negative value will disable periodic dispatch, requiring that you use manual dispatch if you want to send any data to Google Analytics. On the other hand, setting a value of 0 will dispatch each hit immediately if a network connection is available.

Once all hits have been dispatched, periodic dispatch will enter a power save mode and be disabled until another send call is made.

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 Dispatch

Apart from relying on periodic dispatch, there may be times when you want to manually dispatch your hits. For example, you could bundle your dispatches with other HTTP requests made by your application to reduce overhead.

Hits can be manually dispatched by calling dispatch as seen below:

[[GAI sharedTracker] dispatch];