Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save A1iAshoor/12b2673c94ed13a788e7e36c411ed4e7 to your computer and use it in GitHub Desktop.

Select an option

Save A1iAshoor/12b2673c94ed13a788e7e36c411ed4e7 to your computer and use it in GitHub Desktop.
Google Analytics Swift Extension
import UIKit
extension UIViewController {
func setScreeName(name: String) {
self.title = name
self.sendScreenView()
}
func sendScreenView() {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: self.title)
tracker.send(GAIDictionaryBuilder.createScreenView().build())
}
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).build()
tracker.send(trackDictionary)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment