Google Analytics for iOS

Learn how to add usage tracking and other metrics into your iOS app with this Google Analytics Tutorial for iOS! By .

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Opting Out

Last but not least: you can allow your users to opt-out of anonymous usage logging. You can enable an app-level opt-out that will disable Google Analytics across the entire app by setting an optOut property on the tracker object, like so:

[[GAI sharedInstance] setOptOut:YES];

For your clock app, you are going to ask users to opt in or out on launch. First we will create an alert view and show it inside the AppDelegate when the application finished launching. To correctly handle the alert view you must ensure your AppDelegate implements the UIAlertViewDelegate. In your app delegate, SSAppDelegate.h, add the following code:

#import <UIKit/UIKit.h>

@interface SSAppDelegate : UIResponder <UIApplicationDelegate, UIAlertViewDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

Then in your app delegates methods file SSAppDelegate.m add:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     ...
   
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Google Analytics" message:@"With your permission usage information will be collected to improve the application." delegate:self cancelButtonTitle:@"Opt Out" otherButtonTitles:@"Opt In", nil];
    [av show];
   
    return YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            [[GAI sharedInstance] setOptOut:YES];
            break;
        case 1:
            [[GAI sharedInstance] setOptOut:NO];
            break;
           
        default:
            break;
    }
}

This will display the alert view once the application has finished launching giving the user two options:

  1. Opt into logging in which case you will see all of their data on Google Analytics
  2. Opt out of logging in which case nothing will be sent back

Build and run one last time. The app will present you with the choice of opting in or out of usage logging. Be sure not to stab yourself in the back by Opting out of usage tracking while still testing the clock app :]

Opt Out

Where to Go From Here?

You’ve crossed the finish line for this tutorial! I hope what you’ve learned will help you make best use of Google Analytics in your mobile apps. You can download the complete clock project here.

You can do much more once you have data coming in to your Google Analytics account:

  • Experiment with the reports provided for you – you can customize what data is plotted and create more complex reports by crossing a number of tracking parameters
  • Check out the report Behavior / Behaviour flow – it shows you the sequence of how “hits” happened. Effectively if you are conducting an A/B test for a given screen you can check whether the A or B case produces more conversions to your next screen
  • Let your imagination go wild – don’t consider Google Analytics to be just a business tool and try to figure out how it can be useful for you. For example if you are developing a quest game – let GA report every time your player finds an object in the game. This way you’ll figure out if some objects are too hard or too easy to discover on your map! Ka-jing!

If you have any questions, comments or suggestions, feel free to join the discussion below!