I am trying to implement google analytics.. could you guys please help me
-(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];
}
and calling it in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self setGoogleAnalytics];
//
//
//
}
Inside My ViewController implementation
[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];
}
Which version of google analytics, I should download currently I have downloaded google GoogleAnalyticsServicesiOS_3.01.zip (Recommended) as I dont want to work with the beta version GoogleAnalyticsiOS_2.0beta4.zip
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…