5

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

[[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];
4

1 回答 1

0

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

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

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

于 2013-04-24T06:16:40.993 回答