Google Analytics

Google Analytics SDK for iOS v2 (Beta) - Overview

The Google Analytics SDK for iOS makes it easy for developers to collect user engagement data form their apps. This document will provide an overview of the value of the SDK as well as a guide to getting started measuring your app using a single property ID and EasyTracker.

  1. Introduction
  2. Before You Begin
  1. Getting Started
    1. 1. Adding headers and libraries
    2. 2. Initializing the tracker
    3. 3. Implementing screen measurement
  1. Next steps

Introduction

The Google Analytics SDK for iOS makes it easy for developers to collect user engagement data from their apps. Developers can then use Google Analytics reports to measure:

  • The number of active users are using their applications.
  • From where in the world the application is being used.
  • Adoption and usage of specific features.
  • In-app purchases and transactions.
  • The number and type of application crashes.
  • And many other useful metrics.

Before you Begin

Before begin implementing the SDK, make sure you have the following:

Getting Started

There are three steps to getting started with the SDK:

  1. Add headers and libraries to your project
  2. Initialize the tracker
  3. Add screen measurement

After completing these steps, you'll be able to measure the following with Google Analytics:

  • App installations
  • Active users and demographics
  • Screens and user engagement
  • Crashes and exceptions

1. Adding header files and configuring your project

Download the Google Analytics for iOS SDK and add these files from the SDK package to your app:

  • GAI.h
  • GAITracker.h
  • GAITrackedViewController.h
  • GAITransaction.h
  • GAITransactionItem.h
  • libGoogleAnalytics.a

The Google Analytics SDK uses the CoreData and SystemConfiguration frameworks, so you will need to add the following to your application target's linked libraries:

  • libGoogleAnalytics.a
  • CoreData.framework
  • SystemConfiguration.framework

2. Initializing the tracker

To initialize the tracker, import the GAI.h header in your application delegate .m file and add this code to your application delegate's application:didFinishLaunchingWithOptions: method:

- (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 debug to YES for extra debugging information.
  [GAI sharedInstance].debug = YES;
  // Create tracker instance.
  id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];

}
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

Note that in the above example, "UA-YOUR-TRACKING-ID" here is a placeholder for the tracking ID assigned to you when you created your Google Analytics app view (profile). If you are only using one tracking ID in your app, using the default tracker method is best.

3. Implementing screen measurement

To automatically measure views in your app, have your view controllers extend GAITrackedViewController, a convenience class that extends UIViewController, and provide the view name to give to each view controller in your reports. Each time that view is loaded, a screen view will be sent to Google Analytics.

For example, suppose you have an “About” view that you want to measure with a view controller header that looks like this:

@interface AboutViewController : UIViewController

You would update this header to say:

#import "GAITrackedViewController.h"

@interface AboutViewController : GAITrackedViewController

You must also provide the view name to be used in your Google Analytics reports. A good place to put this is the view controller's initializer method, if you have one, or the viewDidAppear: method:

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  self.trackedViewName = @"About Screen";
}
}

As long as trackedViewName is set before sendView: is called, automatic screen measurement will take place. Whenever the view appears, a call to sendView: with the provided view name will be generated.

To learn more about screen measurement, see the Screens Developer Guide.

Congratulations! Your app is now setup to send data to Google Analytics.

Next steps

You can do much more with Google Analytics, including measuring campaigns, in-app payments and transactions, and user interaction events. See the following developer guides to learn how to add these features to your implementation:

  • Advanced Configuration – Learn more about advanced configuration options, including using multiple trackers.
  • Measuring Campaigns – Learn how to implement campaign measurement to understand which channels and campaigns are driving app installs.
  • Measuring Events – Learn how to measure user engagement with interactive content like buttons, videos, and other media using Events.
  • Measuring In-App Payments – Learn how to measure in-app payments and transactions.
  • User timings – Learn how to measure user timings in your app to measure load times, engagement with media, and more.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.