Skip to content

Commit ed4ae2e

Browse files
committed
Track the start & end sessions of TreasureData
1 parent 0f82376 commit ed4ae2e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

iCookTV/AppDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5050
}
5151

5252
func applicationDidEnterBackground(application: UIApplication) {
53+
TreasureData.sharedInstance().endSession(Tracker.sessionsTable)
54+
5355
backgroundTask = application.beginBackgroundTaskWithExpirationHandler { [weak self] in
5456
self?.endBackgroundTask(inApplication: application)
5557
}
@@ -78,6 +80,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7880
TreasureData.sharedInstance().enableAutoAppendModelInformation()
7981
TreasureData.sharedInstance().enableAutoAppendAppInformation()
8082
TreasureData.sharedInstance().enableAutoAppendLocaleInformation()
83+
84+
TreasureData.sharedInstance().defaultDatabase = Tracker.defaultDatabase
85+
TreasureData.sharedInstance().startSession(Tracker.sessionsTable)
8186
}
8287

8388
}

iCookTV/Tracker.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,28 @@ import TreasureData_tvOS_SDK
3030

3131
enum Tracker {
3232

33-
private static let name = "icook_tvos"
33+
static let defaultDatabase = "icook_tvos"
34+
static let sessionsTable = "sessions"
3435

3536
static func track(pageView: PageView) {
3637
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
3738
Debug.print(pageView)
3839
Answers.logCustomEventWithName(pageView.name, customAttributes: pageView.details)
39-
TreasureData.sharedInstance().addEvent(pageView.attributes, database: name, table: "screens")
40+
TreasureData.sharedInstance().addEvent(pageView.attributes, database: defaultDatabase, table: "screens")
41+
#if DEBUG
42+
TreasureData.sharedInstance().uploadEvents()
43+
#endif
4044
}
4145
}
4246

4347
static func track(event: Event) {
4448
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
4549
Debug.print(event)
4650
Answers.logCustomEventWithName(event.name, customAttributes: event.details)
47-
TreasureData.sharedInstance().addEvent(event.attributes, database: name, table: "events")
51+
TreasureData.sharedInstance().addEvent(event.attributes, database: defaultDatabase, table: "events")
52+
#if DEBUG
53+
TreasureData.sharedInstance().uploadEvents()
54+
#endif
4855
}
4956
}
5057

@@ -60,7 +67,10 @@ enum Tracker {
6067
"description": description,
6168
"function": "\(file.typeName).\(function)",
6269
"line": line
63-
], database: name, table: "errors")
70+
], database: defaultDatabase, table: "errors")
71+
#if DEBUG
72+
TreasureData.sharedInstance().uploadEvents()
73+
#endif
6474
}
6575
}
6676

0 commit comments

Comments
 (0)