我在我的应用程序中使用谷歌分析服务来跟踪屏幕视图和按钮按下等事件。但是对于代码可重用性,我想为它创建一个WRAPPER CLASS。请告诉我该怎么做!
跟踪按钮按下事件的代码: -
-(void)logButtonPress:(UIButton *)button{
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Google Analytics"];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"UX"
action:@"touch"
label:[button.titleLabel text]
value:nil] build]];
[tracker set:kGAIScreenName value:nil];
}
页面视图代码: -
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Google Analytics"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
}
答案 0 :(得分:0)
您可以参考此GTrack
https://github.com/gemr/GTrack
手动屏幕跟踪
- (void)viewDidAppear {
[super viewDidAppear];
[[GTTracker sharedInstance] sendScreenEventWithTitle:@"Your Screen Name Here"];
}
发送活动
[[GTTracker sharedInstance] sendAnalyticsEventWithCategory:@"Your Category" action:@"Your Action" label:@"Your Label" value:@(yourValue)];
[[GTTracker sharedInstance] sendAnalyticsEventWithCategory:@"Your Category" action:@"Your Action" label:@"Your Label"];
[[GTTracker sharedInstance] sendAnalyticsEventWithCategory:@"Your Category" action:@"Your Action"];
[[GTTracker sharedInstance] sendAnalyticsEventWithCategory:@"Your Category"];