谷歌分析[[GANTracker sharedTracker] stopTracker];
问题描述:
现在我使用谷歌分析在我的iPad应用程序,用于跟踪浏览量和事件我有下面的代码来实现我所有的viewController和按钮单击事件,但是当我的视线中消失我的应用程序停止/ crash.I已经在viewWillDisappear推杆stopTracker代码[[GANTracker sharedTracker] stopTracker];
方法。谷歌分析[[GANTracker sharedTracker] 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];
答
尝试将呼叫移动到您的AppDelegate的dealloc方法的stopTracker。使其成为该方法的第一行。
你应该只调用stopTracker一次,这应该是在我上面提到的地方。你也应该将共享跟踪器的初始化出你viewControllers,进入的appDelegate的appDidFinishLaunching方法,这同样应该只发生一次。
应该只有一个共享的跟踪器初始化在应用程序启动并最终“停止”时,应用程序终止。