Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
extension UIViewController {
func trackScreen(name: String) {
if let tracker = GAI.sharedInstance().defaultTracker {
tracker.set(kGAIScreenName, value: name)
let screenView = GAIDictionaryBuilder.createScreenView().build()
tracker.send(screenView as [NSObject : AnyObject])
}
}
func trackEvent(category: String, action: String, label: String? = nil, value: NSNumber? = nil) {
if let tracker = GAI.sharedInstance().defaultTracker {
let eventWithCategory = GAIDictionaryBuilder.createEventWithCategory(category, action: action, label: label, value: value).build()
tracker.send(eventWithCategory as [NSObject : AnyObject])
}
}
func trackTiming(category: String, value: NSNumber, name: String? = nil, label: String? = nil){
if let tracker = GAI.sharedInstance().defaultTracker {
let timingWithCategory = GAIDictionaryBuilder.createTimingWithCategory(category, interval: value, name: name, label: label).build()
tracker.send(timingWithCategory as [NSObject : AnyObject])
}
}
func trackMetric(value: String, index: UInt = 1) {
if let tracker = GAI.sharedInstance().defaultTracker {
let metricName = GAIFields.customMetricForIndex(index)
tracker.set(metricName, value: value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.