static let tracker = GAI.sharedInstance().defaultTracker
static func sendScreenName(screen: String) {
guard
let builder = GAIDictionaryBuilder.createScreenView()
else { return }
tracker?.set(kGAIScreenName, value: screen)
tracker?.send(builder.build() as [NSObject : AnyObject])
}
static func trackEvent(category: String, label: String, action: String, value: Int? = nil) {
guard
let builder = GAIDictionaryBuilder.createEvent(withCategory: category, action: action, label: label, value: NSNumber(integerLiteral: value ?? 0))
else { return }
//tracker.set(kGAIScreenName, value: screen)
tracker?.send(builder.build() as [NSObject : AnyObject])
}
static func ecommercePayment(id: String, affiliation: String, revenue: NSNumber, tax: NSNumber, shipping: NSNumber, currencyCode: String){
guard
let builder = GAIDictionaryBuilder.createTransaction(withId: id, affiliation: affiliation, revenue: revenue, tax: tax, shipping: shipping, currencyCode: currencyCode)
else { return }
tracker?.send(builder.build() as [NSObject : AnyObject])
}
在此代码中,是否有必要创建单独的跟踪器,或者我可以这样使用?像静态跟踪器一样。