为什么我的 iOS 应用在 Google Analytics 中的会话时长超过 30 分钟? [英] Why are my iOS app's session lengths 30 min + in Google Analytics?

查看:19
本文介绍了为什么我的 iOS 应用在 Google Analytics 中的会话时长超过 30 分钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

More importantly, how do I fix it?

就好像应用后台运行并没有结束会话一样.

It's as if backgrounding the app doesn't end the session.

推荐答案

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

When your app goes into background mode it needs to tell the analytics to stop tracking.

应用程序委托将类似于:

Application Delegate would have something like:

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

在谷歌的 Easy Tracker 示例,视图控制器在应用状态更改时接收通知.当应用程序进入后台时停止跟踪(大约第 400 行).

In google's Easy Tracker example, a view controller receives notifications when app state changes. Tracking is stopped when app goes into background (Around line 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;
  }

这篇关于为什么我的 iOS 应用在 Google Analytics 中的会话时长超过 30 分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆