Google Analytics for iOS

Guide

Developer Doc

Liner error when trying to install new Google Analytics 3.0 beta

Add AdSupport.framework

Initializing the tracker

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Optional: automatically send uncaught exceptions to Google Analytics.
  [GAI sharedInstance].trackUncaughtExceptions = YES;

  // Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
  [GAI sharedInstance].dispatchInterval = 20;

  // Optional: set Logger to VERBOSE for debug information.
  [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];

  // Initialize tracker.
  id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Y"];

}

Manual Screen Tracking

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"

- (void)viewWillAppear:(BOOL)animated
{
    id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

    // This screen name value will remain set on the tracker and sent with
    // hits until it is set to a new value or to nil.
    [tracker set:kGAIScreenName value:@"Home Screen"];

    [tracker send:[[GAIDictionaryBuilder createAppView] build]];
}

Event Tracking

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"UI_ACTION"     // Event category (required)
                                                      action:@"BUTTON_PRESS"  // Event action (required)
                                                       label:@"DOWNLOAD"          // Event label
                                                       value:[NSNumber numberWithInt:_slideID]] build]];    // Event value