VPNAnalytics.swift
1.46 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
//
// VPNAnalytics.swift
// VPNAnalytics
//
// Created by Mihail Konoplitskyi on 01.09.2022.
//
import Foundation
public final class VPNAnalytics: NSObject {
private static let analyitcsAPIService = AnalyticsAPIService()
private static var isUserInstallEventAlreadyLogged: Bool {
get {
return UserDefaults.standard.bool(forKey: VPNAnalyticsConstants.VPNAnalyticsEvent.install.rawValue)
}
set (newValue) {
UserDefaults.standard.set(newValue, forKey: VPNAnalyticsConstants.VPNAnalyticsEvent.install.rawValue)
}
}
public static func configure(applicationToken: String, baseUrl: String) {
analyitcsAPIService.applicationToken = applicationToken
AnalyticsAPIService.baseUrl = baseUrl
checkAndSendInstallEventIfNeeded()
}
private static func checkAndSendInstallEventIfNeeded() {
guard isUserInstallEventAlreadyLogged else {
// could not find install event in user defaults
// sending this event to server
logEvent(eventType: .install)
return
}
}
public static func logEvent(
eventType: VPNAnalyticsConstants.VPNAnalyticsEvent,
params: [String: String]? = nil) {
analyitcsAPIService.logEvent(eventType: eventType, eventParams: params) {
if eventType == .install {
isUserInstallEventAlreadyLogged = true
}
}
}
}