-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleAnalyticsEngine.swift
More file actions
45 lines (40 loc) · 1.44 KB
/
ConsoleAnalyticsEngine.swift
File metadata and controls
45 lines (40 loc) · 1.44 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
41
42
43
44
45
//
// ConsoleAnalyticsEngine.swift
// CTAnalyticsTestHarnessTests
//
// Created by Sumit Goswami on 18/01/22.
//
import Foundation
/// Prints analytics events to standard output.
///
/// This should be used only for debugging purposes.
/// If you're building for iOS 14+, consider using `LoggerAnalyticsEngine` instead.
/// You can combine this with your actual analytics engine by using `CompoundAnalyticsEngine`.
final public class ConsoleAnalyticsEngine {
/// Category to prepend to each line of console output
///
/// Rough corollary to `Logger.category` in Apple's unified logging system.
public let category = "Analytics"
/// Initialize console analytics engine
public init() { }
}
// MARK: - AnalyticsEngine
/// Conform to `AnalyticsEngine` protocol
extension ConsoleAnalyticsEngine: AnalyticsEngine {
/// Log an analytics event
/// - Parameter event: the event to log
public func track(event: AnalyticsEvent) {
switch event {
case .screenView(let screenName):
print("[\(category)] Screen view: \(screenName)")
case .userProperty(let name, let value):
print("[\(category)] User property: \(name) = \(value)")
case .event(let name, let parameters):
if let parameters = parameters {
print("[\(category)] Event: \(name), \(parameters)")
} else {
print("[\(category)] Event: \(name)")
}
}
}
}