我可以使用像这样的追踪器吗?或为每种方法创建单独的跟踪器? Google Analytics快速

时间:2018-06-19 11:45:07

标签: ios swift xcode google-analytics

   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])
    }

在此代码中,是否有必要创建单独的跟踪器,或者我可以这样使用?像静态跟踪器一样。

0 个答案:

没有答案