Created
February 4, 2016 11:29
-
-
Save tiagomartinho/8e63df1f55f81dfe660c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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