-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleAnalyticsHelper.swift
35 lines (27 loc) · 1.05 KB
/
GoogleAnalyticsHelper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// GoogleAnalyticsHelper.swift
// GoogleAnalyticsHelper
//
// Created by Samuel Beek on 18-02-15.
// Copyright (c) 2015 Samuel Beek. All rights reserved.
//
import UIKit
extension UIViewController {
func trackScreen(name: String) {
self.sendScreenView(name)
}
func sendScreenView(name: String) {
let tracker = GAI.sharedInstance().defaultTracker
let build = GAIDictionaryBuilder.createAppView().set(name, forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])
}
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 as [NSObject : AnyObject])
}
}
// sends the user id to Google Analytics
func setTrackedUserID(id: String){
GAI.sharedInstance().defaultTracker.set("&uid", value: id)
}