-
Notifications
You must be signed in to change notification settings - Fork 0
/
GATrackingManager.swift
41 lines (36 loc) · 1.41 KB
/
GATrackingManager.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
36
37
38
39
40
41
import Foundation
class GATrackingManager {
// GA初期設定(必ず一度実行する)
static func initGa() {
let gai = GAI.sharedInstance()
gai.trackUncaughtExceptions = true
if let path = NSBundle.mainBundle().pathForResource("GoogleService-Info", ofType: "plist") {
if let propertyList = NSDictionary(contentsOfFile: path) as? [String: AnyObject] {
let trackingId = propertyList["TRACKING_ID"] as! String
gai.trackerWithTrackingId(trackingId)
}
}
}
class func sendScreenTracking(screenName : String) {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: screenName)
tracker.send(GAIDictionaryBuilder.createScreenView().build() as [NSObject: AnyObject])
tracker.set(kGAIScreenName, value: nil)
}
/**
GA Event tracking を送信します
:param: category
:param: action
:param: label
:param: value
:returns: void
*/
class func sendEventTracking(category : String, action : String, label : String, value : NSNumber?) {
let tracker = GAI.sharedInstance().defaultTracker
let event = GAIDictionaryBuilder.createEventWithCategory(category,
action: action,
label: label,
value: value).build()
tracker.send(event as [NSObject : AnyObject])
}
}