-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAmplitudeManager.swift
More file actions
73 lines (61 loc) ยท 1.95 KB
/
AmplitudeManager.swift
File metadata and controls
73 lines (61 loc) ยท 1.95 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Foundation
import AmplitudeSwift
/// Amplitude Analytics ๊ด๋ฆฌ์
public final class AmplitudeManager {
public static let shared = AmplitudeManager()
private var amplitude: Amplitude?
private init() {}
/// Amplitude ์ด๊ธฐํ
/// - Parameters:
/// - apiKey: Amplitude API Key
/// - userId: ์ฌ์ฉ์ ID (์ต์
๋)
public func initialize(apiKey: String, userId: String? = nil) {
amplitude = Amplitude(configuration: Configuration(
apiKey: apiKey
))
if let userId = userId {
setUserId(userId)
}
}
/// ์ฌ์ฉ์ ID ์ค์
/// - Parameter userId: ์ฌ์ฉ์ ID
public func setUserId(_ userId: String) {
amplitude?.setUserId(userId: userId)
}
/// ์ฌ์ฉ์ ์์ฑ ์ค์
/// - Parameter properties: ์ฌ์ฉ์ ์์ฑ
public func setUserProperties(_ properties: [String: Any]) {
let identify = Identify()
properties.forEach { key, value in
identify.set(property: key, value: value)
}
amplitude?.identify(identify: identify)
}
/// ์ด๋ฒคํธ ์ ์ก
/// - Parameter event: AnalyticsEvent
public func track(_ event: AnalyticsEvent) {
guard let amplitude = amplitude else {
print("โ ๏ธ Amplitude๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.")
return
}
let eventProperties = event.properties.isEmpty ? nil : event.properties
amplitude.track(
eventType: event.eventName,
eventProperties: eventProperties
)
#if DEBUG
print("๐ [Analytics] \(event.eventName)")
if let properties = eventProperties {
print(" Properties: \(properties)")
}
#endif
}
/// ์ด๋ฒคํธ ๋ฒํผ ์ฆ์ ์ ์ก
public func flush() {
amplitude?.flush()
}
/// Amplitude ๋ฆฌ์
(๋ก๊ทธ์์ ์ ์ฌ์ฉ)
public func reset() {
amplitude?.reset()
}
}