2012-12-24 88 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]; 
}