Monday 4 March 2013

google analytics in iphone app


Overview

The Google Analytics SDK for iOS makes it easy for native iOS developers to collect user engagement data form their applications. Developers can then use the 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.
  • Crashes and exceptions.
  • And many other useful metrics...

Getting Started

The Google Analytics for Mobile Apps SDKs make it easy for you to implement Google Analytics in your mobile application.

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'sapplication: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 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 extendsUIViewController, 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 viewDidLoad method:
- (void)viewDidLoad {
  [super viewDidLoad];
  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 tosendView: 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.


No comments:

Post a Comment