2012-12-24 56 views
1

我开始使用适用于iOS本机应用程序的Goole Analytics v2.0beta3。 我用下面的代码启动一个会话:Google Analytics(分析)V2 iOS - 会话持续时间始终为0.0

[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

有没有人遇到这个问题?

谢谢

回答

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]; 
}