我正在尝试实施谷歌分析..你们能帮帮我吗
-(void) setGoogleAnalytics{
// Initialize tracker.
self.tracker = [[GAI sharedInstance] trackerWithName:@"ipad app"
trackingId:kTrackingID];
NSDictionary *appDefaults = @{kAllowTracking: @(YES)};
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
// User must be able to opt out of tracking
[GAI sharedInstance].optOut =
![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];
// 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 = 5;
// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];
[[GAI sharedInstance] setTrackUncaughtExceptions:YES];
}
并调用它
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self setGoogleAnalytics];
//
//
//
}
在我的 ViewController 实现中
[self dispatchEvent:@"Purchase Done"];
[self trackViewName:NSStringFromClass([self class])];
-(void) trackViewName:(NSString *) strClassName{
[[GAI sharedInstance] defaultTracker];
self.screenName=[NSString stringWithFormat:@"%@",strClassName];
[self.tracker send:[[NSDictionary alloc] initWithObjectsAndKeys:strClassName,@"ViewName", nil]];
[[GAI sharedInstance] dispatch];
}
- (void)dispatchEvent:(NSString *)strButtonText{
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"button_press" // Event action (required)
label:strButtonText // Event label
value:nil] build]]; // Event value = [[GAI sharedInstance] defaultTracker];
[[GAI sharedInstance] dispatch];
}
目前我应该下载哪个版本的谷歌分析我已经下载了谷歌 GoogleAnalyticsServicesiOS_3.01.zip(推荐),因为我不想使用测试版 GoogleAnalyticsiOS_2.0beta4.zip