为什么我的iOS应用会话长度为30分钟+在Google Analytics中?

che*_*are 8 google-analytics ios

更重要的是,我该如何解决?

这就好像后台应用程序没有结束会话.

Ale*_*x L 13

当您的应用进入后台模式时,它需要告诉分析停止跟踪.

应用程序代表将具有以下内容:

-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[GANTracker sharedTracker] stopTracker];
}
Run Code Online (Sandbox Code Playgroud)

在Google的Easy Tracker示例中,视图控制器会在应用状态更改时收到通知.当应用程序进入后台时(第400行附近),会停止跟踪.

if ([application applicationState] == UIApplicationStateBackground) {
    if (self.state == EasyTrackerStateForeground) {
      // Transitioned from foreground to background. Generate the app stop
      // event, and stop the tracker.
      NSLog(@"Transitioned from foreground to background.");
      NSError *error = nil;
      if (![[GANTracker sharedTracker] trackEvent:@""
                                           action:@""
                                            label:@""
                                            value:0
                                        withError:&error]) {
        NSLog(@"Error tracking foreground event: %@", error);
      }
      // TODO(fmela): make this time period a constant.
      if (![[GANTracker sharedTracker] dispatchSynchronous:2.0]) {
        NSLog(@"Synchronous dispatch on background failed!");
      }
      [[GANTracker sharedTracker] stopTracker];
    }
    self.state = EasyTrackerStateBackground;
  }
Run Code Online (Sandbox Code Playgroud)