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

问题描述

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



好像背景应用程序不会结束会话。



Application Delegate会有如下所示:

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

在谷歌的示例,视图控制器接收通知当应用状态发生变化时当应用进入后台时跟踪停止(大约400行)。

  if([application applicationState] == UIApplicationStateBackground){
if(self.state == EasyTrackerStateForeground){
//从前景转换到背景。生成应用程序停止
//事件,并停止跟踪器。
NSLog(@从前景转换到背景。);
NSError * error = nil;
if(![[GANTracker sharedTracker] trackEvent:@
action:@
label:@
value:0
withError:&错误]){
NSLog(@错误跟踪前景事件:%@,错误);
}
// TODO(fmela):使这个时间段保持不变。
if(![[GANTracker sharedTracker] dispatchSynchronous:2.0]){
NSLog(@Background synchronization failed!);
}
[[GANTracker sharedTracker] stopTracker];
}
self.state = EasyTrackerStateBackground;
}


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

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分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:43