-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyticsManager.swift
105 lines (84 loc) · 3.64 KB
/
AnalyticsManager.swift
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// AnalyticsManager.swift
// swc
//
// Created by Arsen Gasparyan on 06/03/16.
// Copyright © 2016 SweatCo LTD. All rights reserved.
//
import UIKit
import WatchConnectivity
class AnalyticsManager: NSObject {
static let sharedManager = AnalyticsManager()
var providers = [AnalyticsProtocol]()
var trackPushTokenReceived = false
class func set(profile: Profile) {
sharedManager.providers.forEach { $0.set(profile: profile) }
let watch = WCSession.default()
let experiments: NSArray = profile.experiments as NSArray
addUserProperty("experiments", value: experiments)
addUserProperty("watch.is_paired", value: watch.isPaired as NSObject)
addUserProperty("watch.app_installed", value: watch.isWatchAppInstalled as NSObject)
}
class func removeProfile() {
sharedManager.providers.forEach { $0.removeProfile() }
}
class func log(event: AnalyticsEvents) {
sharedManager.providers.forEach { $0.log(event: event) }
}
class func log(event: String) {
sharedManager.providers.forEach { logger in
logger.log(event: event, params: [String: String](), outOfSession: false)
}
}
class func log(event: String, params: [String: String]) {
sharedManager.providers.forEach { logger in
logger.log(event: event, params: params, outOfSession: false)
}
}
class func log(name: String, params: [String: String], outOfSession: Bool) {
sharedManager.providers.forEach { logger in
logger.log(event: name, params: params, outOfSession: outOfSession)
}
}
class func log(screen: String) {
sharedManager.providers.forEach { $0.log(screen: screen, params: [String: String]()) }
}
class func log(screen: String, params: [String: String]) {
sharedManager.providers.forEach { $0.log(screen: screen, params: params) }
}
class func logOfferPurchase(_ offer: Offer, marketplace: String) {
sharedManager.providers.forEach {
$0.log(revenue: Double(offer.price), product: "offer.\(offer.id)", contentType: "offer_purchase")
}
log(event: .offerPurcahseSuccess(offer: offer, marketplace: marketplace))
}
class func logUpgradeToMembership(_ membership: Subscription!, from: Subscription!) {
guard let membership = membership, let from = from else { return }
sharedManager.providers.forEach {
$0.log(revenue: Double(membership.price), product: "membership.\(membership.name)", contentType: "membership_upgrade")
}
log(event: .membershipUpgradeSuccess(from: from, to: membership))
}
class func logCoinTransfer(_ recipient: String, revenue: Double) {
sharedManager.providers.forEach {
$0.log(revenue: revenue, product: "coin_transfer.\(recipient)", contentType: "coin_transfer")
}
log(event: .sentCoinsTranferSuccess(recipient: recipient, amount: revenue))
}
class func logWalkchainSubmit(_ walkchain: Walkchain!) {
guard let walkchain = walkchain else { return }
log(event: .walkchainAccepted(walkchain: walkchain))
}
class func addUserProperty(_ key: String, value: NSObject!) {
guard let value = value else { return }
sharedManager.providers.forEach {
$0.addUserProperty(key, value: value)
}
}
class func addUserPropertyOnce(_ key: String, value: NSObject!) {
guard let value = value else { return }
sharedManager.providers.forEach {
$0.addUserPropertyOnce(key, value: value)
}
}
}