2013年10月15日火曜日

Google Analytics for iOS v3(Beta)

※注意:この内容は古い情報です


以下に最新(2014/2/27 ver3.0.3c)の情報を記載したのでそちらを参照ください。
http://kojisatoapp.blogspot.jp/2014/02/iosgoogle-analytics.html


ライブラリ追加


  • GAI.h
  • GAITracker.h
  • GAITrackedViewController.h
  • GAIDictionaryBuilder.h
  • GAIFields.h
  • GAILogger.h
  • libGoogleAnalyticsServices.a



フレームワークの追加


  • AdSupport.framework
  • libGoogleAnalyticsServices.a
  • CoreData.framework
  • SystemConfiguration.framework
  • libz.dylib



初期処理

#import "GAI.h"

- (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 Logger to VERBOSE for debug information.
  [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];

  // Initialize tracker.
  [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Y"];

}


ページのトラッキング(自動計測)

#import "GAITrackedViewController.h"

@interface HomeViewController : GAITrackedViewController

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


ページのトラッキング(手動)

#import "GAI.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"

// May return nil if a tracker has not already been initialized with a
// property ID.
id tracker = [[GAI sharedInstance] defaultTracker];

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName value:@"Home Screen"];

[tracker send:[[GAIDictionaryBuilder createAppView] build]];


イベントのトラッキング

// May return nil if a tracker has not already been initialized with a property
// ID.
id<GAITracker> = [[GAI sharedInstance] defaultTracker];

[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"     // Event category (required)
                                                      action:@"button_press"  // Event action (required)
                                                       label:@"play"          // Event label
                                                       value:nil] build]];    // Event value

0 件のコメント:

コメントを投稿