omnivore/apple/OmnivoreKit/Sources/Utils/EventTracking/TrackableEvents.swift

73 lines
2.1 KiB
Swift
Raw Permalink Normal View History

2022-04-28 17:04:53 +00:00
import Foundation
2022-04-28 18:44:18 +00:00
public enum TrackableEvent {
case linkRead(linkID: String, slug: String, reader: String, originalArticleURL: String)
case debugMessage(message: String)
2022-06-15 18:33:03 +00:00
case backgroundFetch(jobStatus: BackgroundFetchJobStatus, itemCount: Int, secondsElapsed: Int)
2024-02-05 09:34:27 +00:00
case audioSessionStart(linkID: String, voice: String, voiceProvider: String)
2022-09-22 04:05:32 +00:00
case audioSessionEnd(linkID: String, timeElapsed: Double)
2024-05-20 13:08:21 +00:00
case digestOpened(digestID: String)
2022-06-15 18:33:03 +00:00
}
public enum BackgroundFetchJobStatus: String {
case success
case failed
case authFailure
case timeExpired
2022-04-28 17:04:53 +00:00
}
2022-04-28 18:44:18 +00:00
public extension TrackableEvent {
var name: String {
2022-04-28 17:04:53 +00:00
switch self {
2022-04-28 18:44:18 +00:00
case .linkRead:
return "link_read"
case .debugMessage:
return "debug_message"
2022-06-15 18:33:03 +00:00
case .backgroundFetch:
return "background_fetch"
2022-09-22 04:05:32 +00:00
case .audioSessionStart:
return "audio_session_start"
case .audioSessionEnd:
return "audio_session_end"
2024-05-20 13:08:21 +00:00
case .digestOpened:
return "digest_opened"
2022-04-28 17:04:53 +00:00
}
}
2022-04-28 18:44:18 +00:00
var properties: [String: String]? {
2022-04-28 17:04:53 +00:00
switch self {
case let .linkRead(linkID: linkID, slug: slug, reader: reader, originalArticleURL: originalArticleURL):
2022-04-28 18:44:18 +00:00
return [
"link": linkID,
"slug": slug,
"reader": reader,
2022-04-28 18:44:18 +00:00
"url": originalArticleURL
]
case let .debugMessage(message: message):
return ["message": message]
2022-06-15 18:33:03 +00:00
case let .backgroundFetch(jobStatus: jobStatus, itemCount: itemCount, secondsElapsed: secondsElapsed):
return [
"status": jobStatus.rawValue,
"seconds_elapsed": String(secondsElapsed),
"fetched_item_count": String(itemCount)
]
2024-02-05 09:34:27 +00:00
case let .audioSessionStart(linkID: linkID, voice: voice, voiceProvider: voiceProvider):
2022-09-22 04:05:32 +00:00
return [
2024-02-05 09:34:27 +00:00
"link": linkID,
"voice": voice,
"voiceProvider": voiceProvider
2022-09-22 04:05:32 +00:00
]
case let .audioSessionEnd(linkID: linkID, timeElapsed: timeElapsed):
return [
"link": linkID,
"timeElapsed": String(timeElapsed)
]
2024-05-20 13:08:21 +00:00
case let .digestOpened(digestID: digestID):
return [
"channel": "push",
"digestID": digestID
]
2022-04-28 17:04:53 +00:00
}
}
}