我开始将Goole Analytics v2.0beta3用于iOS原生应用。 我使用以下代码开始会话:
[GAI sharedInstance].trackUncaughtExceptions = YES;
[GAI sharedInstance].dispatchInterval = 20;
[GAI sharedInstance].debug = YES;
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-X"];
[GAI sharedInstance].defaultTracker = tracker;
[tracker setAnonymize:YES];
BOOL res = [tracker trackEventWithCategory:@"cat" withAction:@"act" withLabel:@"label" withValue:[NSNumber numberWithInt:1]];
[[GAI sharedInstance] dispatch];
但是,我不知道如何结束会话,我得到的会话持续时间总是0.0
有没有人遇到过这个问题?
谢谢
答案 0 :(得分:2)
我会检查并查看您的跟踪器是否设置正确。我的设置代码如下
[GAI sharedInstance].debug = YES;
[GAI sharedInstance].dispatchInterval = 20;
[GAI sharedInstance].trackUncaughtExceptions = YES;
self.tracker = [[GAI sharedInstance] trackerWithTrackingId:kTrackingId];
NSLog(@"what is tracker %@ / default tracker %@?", self.tracker, [GAI sharedInstance].defaultTracker);
其中self.tracker为@property (strong, nonatomic) id <GAITracker> tracker;
我正在获得正确的会话跟踪信息。也许尝试拔出代码,直到找到导致问题的原因?
此外,解决方法可能是这样的。
- (void)applicationDidBecomeActive:(UIApplication *)application
{
appBecameActive = [NSDate date];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSDate *appClosing = [NSDate date];
NSTimeInterval sessionLength = [appClosing timeIntervalSinceDate:appBecameActive];
[[GAI sharedInstance].defaultTracker trackTimingWithCategory:@"sessionLength"
withValue:sessionLength
withName:@"appWentToBackground"
withLabel:nil];
}
答案 1 :(得分:0)
根据Google Analytics v3,会话行为发生了变化。如果您在使用最新版本时遇到这些问题,请查看我的修复程序: