Created
April 3, 2017 15:40
-
-
Save Quaggie/86df8a49688cbda879915e05a0ecd206 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Analytics helper created by @Quaggie - Jonathan Bijos | |
| import UIKit | |
| struct Analytics { | |
| fileprivate let viewController: UIViewController | |
| fileprivate let tracker = GAI.sharedInstance().defaultTracker | |
| init (forScreen viewController: UIViewController) { | |
| self.viewController = viewController | |
| } | |
| func startTracking () { | |
| let screenView = GAIDictionaryBuilder.createScreenView().build() as NSDictionary | |
| guard | |
| let tracker = tracker, | |
| let build = screenView as? [AnyHashable: Any] | |
| else { return } | |
| tracker.set(kGAIScreenName, value: String(describing: viewController)) | |
| tracker.send(build) | |
| } | |
| } | |
| // ------------- On the UIViewController ------------- | |
| class HomeViewController: UIViewController { | |
| lazy var analytics = Analytics(forScreen: self) | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| } | |
| override func viewWillAppear() { | |
| super.viewWillAppear() | |
| analytics.startTracking() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment