2012-03-27 35 views

回答

13

當你的應用程序進入它需要告訴分析停止跟蹤後臺模式。

應用程序的代理會碰到這樣的:

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

在谷歌的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; 
    } 
+0

你好,你確定這是會議結束GA會看到它嗎? – 2012-04-20 21:25:00

+0

對不起,按回車鍵而不是shift +回車。這是其餘的: 我有一個測試應用程序,並打開調試模式,並在看調度命中。 所以我的應用程序流程如下所示: 我啓動應用程序並啓動頁面視圖。 我點擊主頁按鈕並將應用程序發送到背景。 我點擊應用程序圖標,將應用程序帶回前臺,當我這樣做時,我發起了一個事件。 這裏有__utma位從我__utm.gif點擊: 頁面視圖:1.334475189.1334947296.1334956043.1334956141.13 事件:1.334475189.1334947296.1334956141.1334956163.14 觀看次數是指這裏遞增。它不應該是1嗎? – 2012-04-20 21:33:22

+0

***在*** applicationDidEnterBackground *** stopTracking ***方法沒有在我的情況下結束會話,我在我的項目中使用ARC,我不能像使用GA例子那樣使用dealloc方法。沒有其他方式結束會議? – 2012-04-30 01:49:59

-2

結束會話時,應用程序切換到後臺,使用

applicationWillResignActive 

,也許放一下:空白或東西在你的網頁流量。 (假設;)

保存位置和

applicationDidBecomeActive 

重新加載它或閱讀更多here

+1

假設不屬於答案 - 另外,這個問題是關於如何停止應用中的跟蹤器,而不是webview。另外,用戶正在尋找命令來放入'applicationWillResignActive'來停止跟蹤器。 – tkone 2012-04-01 22:34:34

相關問題