1

I started using Goole Analytics v2.0beta3 for iOS native app. I start a session with the following code:

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

However, I don't know how to end the session and the session duration I get is always 0.0

Has anyone encountered this issue ?

Thanks

4

2 回答 2

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];
}
于 2012-12-28T22:32:23.993 回答
0

根据 Google Analytics v3,会话行为发生了变化。如果您在使用最新版本时遇到这些问题,请在此处查看我的修复:

https://stackoverflow.com/a/26882024/1485701

于 2014-11-12T08:10:01.407 回答