Google Analytics for iOS - 手动屏幕跟踪功能无效

时间:2016-03-12 13:17:12

标签: ios swift analytics

我在iOS上遇到屏幕跟踪问题。我这样做就像它来自Google的示例应用程序:

    let tracker = GAI.sharedInstance().defaultTracker
    tracker.set("My screen", value: "Value")
    tracker.send(GAIDictionaryBuilder.createScreenView().build() as [NSObject : AnyObject])

它不起作用。它正确地跟踪事件,当我将View Controller子类化为GAITrackedViewController时,它是跟踪屏幕。但是,我不想将视图控制器子类化为跟踪屏幕。有没有人有想法?

1 个答案:

答案 0 :(得分:1)

您不必继承ViewControllers,只需执行此操作:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    let googleTracker = GAI.sharedInstance().trackerWithTrackingId("UA-YOUR_TRACKER_ID")
    googleTracker.set(kGAIScreenName, value: "MyPageName")
    let builder = GAIDictionaryBuilder.createScreenView()
    googleTracker.send(builder.build() as [NSObject : AnyObject])
}

当然,您不需要每次都创建“googleTracker”对象,在某个中心位置创建并从那里获取它。