更重要的是,我该如何修复它?
就好像后台应用程序不会结束 session 。
最佳答案
当您的应用进入后台模式时,它需要告诉分析停止跟踪。
Application Delegate 会是这样的:
-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[GANTracker sharedTracker] stopTracker];
}
在谷歌的 Easy Tracker例如, View Controller 在应用程序状态更改时接收通知。当应用程序进入后台时(第 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 - 为什么我的 iOS 应用程序在 Google Analytics 中的 session 时长超过 30 分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9895924/