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

时间:2012-03-27 19:01:59

标签: ios google-analytics

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

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

4 个答案:

答案 0 :(得分:13)

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

Application Delegate将具有以下内容:

-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[GANTracker sharedTracker] stopTracker];
}

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

答案 1 :(得分:0)

它表示如果用户在30分钟内有一个事件,它会将其视为同一个会话。所以这意味着如果用户在使用您的应用程序30分钟内回来。

https://developers.google.com/analytics/devguides/collection/ios/v2/sessions

答案 2 :(得分:-1)

这可能会有所帮助:Updating Google Session Tracking

它谈论网络,但特别提到了一个30分钟的规则。

答案 3 :(得分:-2)

在应用转到后台时结束会话,请使用

applicationWillResignActive

并且可能会出现:空白或您的网页浏览中的内容。 (假设;)

保存位置并在

中重新加载
applicationDidBecomeActive

或阅读更多here