--- UPDATED ---
Here is how I fixed it:
1 - add these properties and the #define directive (if you do not have it in the application) in AppDelegate:
2- in viewDidLoad I use dispatchInterval as 20 and initialize the generic tracker instance:
[GAI sharedInstance].dispatchInterval = 20;
3 - add this method for your AppDelegate:
4- at the end of the applicationDidEnterBackground call the sendHitsInBackground method:
- (void)applicationDidEnterBackground:(UIApplication *)application {
5 - Add the executeFetchWithCompletionHandler method and call sendHitsInBackground:
// In case the app was sent into the background when there was no network connection, we will use // the background data fetching mechanism to send any pending Google Analytics data. Note that // this app has turned on background data fetching in the capabilities section of the project. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if (IS_IOS7_AND_UP) [self sendHitsInBackground]; completionHandler(UIBackgroundFetchResultNewData); }
and Google Analytics will begin to work after these efforts. I try this in several applications. If you have any questions, let me know.
In any case, I do not trust only one analytical tool, some alternatives are needed. I suggest you use Flurry and / or Crashlytics (Fabric). Flurry acquired Yahoo, Crashlytics acquired by Twitter. Why Fabric, because it has so many features that you fall in love with!
Here you can try:
Fabric: https://fabric.io
Flurry: http://www.flurry.com
You can call them in
didFinishLaunchingWithOptions ... [self yourAnalyticServices];
And your code is as follows:
- (void)yourAnalyticServices { //Flurry Analytics [Flurry setAppVersion:kAppVersion]; [Flurry startSession:kFlurryAnalyticsID]; // [Flurry setCrashReportingEnabled:NO]; [Flurry setUserID:[NSString stringWithFormat:@"%@", kUserUUID]]; //Google Analytics // Optional: automatically send uncaught exceptions to Google Analytics. //[GAI sharedInstance].trackUncaughtExceptions = YES; // Optional: set Google Analytics dispatch interval to eg 20 seconds. [GAI sharedInstance].dispatchInterval = 20; // Optional: set Logger to VERBOSE for debug information. //[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose]; // Initialize tracker. [[GAI sharedInstance] trackerWithTrackingId:MY_GoogleAnalyticsID]; //Crashlytics [Fabric with:@[CrashlyticsKit]]; }