-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggerAnalyticsEngine.swift
More file actions
40 lines (36 loc) · 1.34 KB
/
LoggerAnalyticsEngine.swift
File metadata and controls
40 lines (36 loc) · 1.34 KB
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
//
// LoggerAnalyticsEngine.swift
// CTAnalytics
//
// Created by Sumit Goswami on 17/01/22.
//
import Foundation
import os
/// Logs analytics events to Apple's unified logging system.
///
/// This should be used only for debugging purposes.
/// You can combine this with your actual analytics engine by using `CompoundAnalyticsEngine`.
final public class LoggerAnalyticsEngine {
private let logger = Logger(subsystem: "com.codeandtheory.ctanalytics.core", category: "Analytics")
/// Initialize logger analytics engine
public init() { }
}
/// Conform to `AnalyticsEngine` protocol
extension LoggerAnalyticsEngine: AnalyticsEngine {
/// Log an analytics event
/// - Parameter event: the event to log
public func track(event: AnalyticsEvent) {
switch event {
case .screenView(let screenName):
logger.debug("Screen view: \(screenName, privacy: .public)")
case .userProperty(let name, let value):
logger.debug("User property: \(name, privacy: .public) = \(value, privacy: .private)")
case .event(let name, let parameters):
if let parameters = parameters {
logger.debug("Event: \(name, privacy: .public), \(parameters, privacy: .private)")
} else {
logger.debug("Event: \(name, privacy: .public)")
}
}
}
}