Wednesday, September 4, 2013

Google Analytics Integration in ios ---- IOS SDK

Google Analytics, Create a new profile
You can download it from: http://code.google.com/apis/analytics/docs/tracking/mobileAppsTracking.html.

Step 1: Add a new websites profile.

Step 2: Select Add a Profile for a new domain.
Step 3: Enter URL (no need to be a live URL, e.g.: testapp.articledean.com). Google never uses this URL; this entry is just for our reference, so a meaningful URL will do.
Step 4: Select the Country and TimeZone.
Step 5: Click Finish, and Google Analytics will give you a Web Property ID that starts with UA. Note it down; this is the unique identification of your application. This ID looks like: Web Property ID: UA-12345678-2 (Sample ID).

Download and Integrate the Google Analytics Library for iPhone Applications
Download link: Analytics SDK for iPhone.
Download and extract the library. The following two files are the key components of the Google Analytics Library.
    1.    GANTracker.h
    2.    libGoogleAnalytics.a
Copy the above files into the library folder of you iPhone application in XCode. Make sure that you are copying the files into the destination folder.

Google Analytics Library requires "CFNetwork" and "libsqlite3.0.dylib
Using the Google Analytics Library in code
Import the "GANTracker.h" file into your application delegate class. In the "applicationDidFinishLaunching()" method, initialize the tracker object.
#import "GANTracker.h"
[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-12345678-2"
                               dispatchPeriod:20
                               delegate:nil];
Google Analytics supports two levels of tracking: "PageViews" and "Events". "Page Views" are like tracking regular web pages."Events" tracking can be used on button clicks, radio button selections, text box entries etc.

Page Views sample code in the applicationDidFinishLaunching method
NSError *error;
if (![[GANTracker sTracker] trackPageview:@"/applicationlaunched"
                                        withError:&err]) {
     // Error Handling
   }
Events sample code, when an event fires (like button click)
- (IBAction) clickMe:(id) sender
{
        NSError *err;
        if (![[GANTracker sTracker] trackEvent:@"clkButton"
                                            action:@"trackMyPage"
                                            label:@"sampleLabel"
                                            value:-1
                                        withError:&err]) {
               // Error Handling

        }
}
    •    "clkButton" is a group that represents a Button Click Event category. You can track all your button clicks by using this user defined group.
    •    "trackMyPage" is the event name when my button is clicked; I will call the "trackMyPage" event method.
    •    "sampleLabel" is just a label that gives you information about your tracking.

No comments:

Post a Comment