Google Analytic [[GANTracker sharedTracker] stopTracker];

Nit*_*tin 5 google-analytics google-analytics-api

现在我在我的Ipad应用程序中使用Google Analytic来跟踪我在我的所有viewController和按钮点击事件的代码下面实现的网页浏览和事件,但是当我的视图消失时,我的应用程序停止/崩溃.我[[GANTracker sharedTracker] stopTracker];在viewWillDisappear方法中放置了stopTracker代码.

[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-12345678-1"
                                       dispatchPeriod:kGANDispatchPeriodSec
                                             delegate:nil];

NSError *error;
if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1
                                                     name:@"iPad3"
                                                    value:@"iv1"
                                                withError:&error]) {
    // Handle error here
}

if (![[GANTracker sharedTracker] trackEvent:@"my_category"
                                     action:@"my_action"
                                      label:@"my_label"
                                      value:-1
                                  withError:&error]) {
    // Handle error here
}

if (![[GANTracker sharedTracker] trackPageview:@"/app_entry_point_prashant"
                                     withError:&error]) {
    // Handle error here
}
[[GANTracker sharedTracker] stopTracker];
Run Code Online (Sandbox Code Playgroud)

men*_*b0t 0

尝试将对 stopTracker 的调用移至 AppDelegate 的 dealloc 方法。使其成为该方法中的第一行。

你应该只调用 stopTracker 一次,并且应该在我上面提到的地方。您还应该将共享跟踪器的初始化从 viewControllers 移出并移至 appDelegate 的 appDidFinishLaunching 方法中,同样,这应该只发生一次。

应该只有一个共享跟踪器在应用程序启动时初始化,并最终在应用程序终止时“停止”。