Monday, March 28, 2016

A Day with "Google Analytics"


Hey Folks,

Today got a chance to work on with Google Analytics.
Amazing...
Loved playing with it.

Presenting basic info so that you guys can start playing with it too within your iOS Apps :)

Let's Start..


A) Accounts & Guides

  • Sign up with an email id
  • Provide an Account name & App name that you want to work with
  • Agree with terms & conditions and you will be provided a TRACKING ID
  • Get your iOS Starting Guide that will help you in adding analytics to your app and screens : “https://developers.google.com/analytics/devguides/collection/ios/v3/"
  • You get a sample app to to start with





B) App Info

  • Analytics uses CocoaPods to install and manage dependencies.
  • Remember to Choose between Objective-C or Swift
  • Create / Choose App Name
  • Download googleServices-info.plist file and drag into your root folder

 
C) CocoaPods 
  • Create a text file named as podfile with following content :
platform :ios, ‘9.1’ 
use_frameworks! 

target ‘PullToRefresh’ 
   do  pod 'Google/Analytics' // you can mention all dependencies here
 end
  • Open Terminal and write pod install
  • If you prefer not to use CocoaPods to manage library dependencies, you can download and directly use the Google Analytics Services SDK.


D) Project

  • Add Analytics inside AppDelegate #import <Google/Analytics.h>
  • Then, override the didFinishLaunchingWithOptions method to configure GGLContext
  • Here you’ll send a named screen view to Analytics whenever the user opens or changes screens on your app. Open a View Controller that you'd like to track, or if this is a new application, open the default view controller.

- (void)viewWillAppear:(BOOL)animated
{
    id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
    [tracker set:kGAIScreenName value:@"MAIN SCREEN"];
    [tracker send:[[GAIDictionaryBuilder createScreenView] build]];
}


Note: You can add tracking code to every UIViewController that represents a screen, whether shown to your user imperatively (via code) or via storyboard. Set a name inside everyUIViewController if you want to differentiate between screen views for your app in Analytics. All activity recorded on the shared tracker sends the most recent screen name until replaced or cleared (set to nil).


E) View the Status in dashboard











Hope it helps :)





7 comments:

  1. can you tell me same for simple web application except IOS

    ReplyDelete
  2. Check this for web application :
    https://developers.google.com/analytics/devguides/collection/analyticsjs/

    ReplyDelete
  3. Good one swati.. Information is really helpful for iOS developer ��

    ReplyDelete