2016-05-11 55 views
2

這是我第一次整合谷歌分析在我app.I'm只是跟着這個正式文件here谷歌Analytics(分析)集成在iOS的SWIFT

我已經有一個跟蹤ID。我不想創建配置文件。 如何使用該跟蹤器ID以及如何整合Google分析?

+0

創建配置文件並用新的跟蹤器ID替換您的跟蹤器ID。 – Sahil

回答

1
Create extension of UIView Conroller. 

extension UIViewController { 
    func setScreeName(name: String) { 
     self.title = name 
     self.sendScreenView() 
    } 

    func sendScreenView() { 
     let tracker = GAI.sharedInstance().defaultTracker 
     tracker.set(kGAIScreenName, value: self.title) 
     let builder = GAIDictionaryBuilder.createScreenView() 
     tracker.send(builder.build() as [NSObject : AnyObject]) 
    } 

    func trackEvent(category: String, action: String, label: String, value: NSNumber?) { 
     let tracker = GAI.sharedInstance().defaultTracker 
     let trackDictionary = GAIDictionaryBuilder.createEventWithCategory(category, action: action, label: label, value: value) 
     tracker.send(trackDictionary.build() as [NSObject : AnyObject]) 
    } 
} 

For Each view Controller viewdidload() you add following code 
self.title = self.navigationItem.title! 
    self.sendScreenView()