@@ -29,7 +29,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
29
29
private var config : IterableConfig
30
30
private( set) var lastCriteriaFetch : Double = 0
31
31
32
- // Tracks an anonymous event and store it locally
32
+ /// Tracks an anonymous event and store it locally
33
33
public func trackAnonEvent( name: String , dataFields: [ AnyHashable : Any ] ? ) {
34
34
var body = [ AnyHashable: Any] ( )
35
35
body. setValue ( for: JsonKey . eventName, value: name)
@@ -41,11 +41,12 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
41
41
storeEventData ( type: EventType . customEvent, data: body)
42
42
}
43
43
44
+ /// Tracks an anonymous user update event and store it locally
44
45
public func trackAnonUpdateUser( _ dataFields: [ AnyHashable : Any ] ) {
45
46
storeEventData ( type: EventType . updateUser, data: dataFields, shouldOverWrite: true )
46
47
}
47
48
48
- // Tracks an anonymous purchase event and store it locally
49
+ /// Tracks an anonymous purchase event and store it locally
49
50
public func trackAnonPurchaseEvent( total: NSNumber , items: [ CommerceItem ] , dataFields: [ AnyHashable : Any ] ? ) {
50
51
var body = [ AnyHashable: Any] ( )
51
52
body. setValue ( for: JsonKey . Body. createdAt, value: IterableUtil . secondsFromEpoch ( for: dateProvider. currentDate) )
@@ -57,22 +58,22 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
57
58
storeEventData ( type: EventType . purchase, data: body)
58
59
}
59
60
60
- // Tracks an anonymous cart event and store it locally
61
+ /// Tracks an anonymous cart event and store it locally
61
62
public func trackAnonUpdateCart( items: [ CommerceItem ] ) {
62
63
var body = [ AnyHashable: Any] ( )
63
64
body. setValue ( for: JsonKey . Body. createdAt, value: IterableUtil . secondsFromEpoch ( for: dateProvider. currentDate) )
64
65
body. setValue ( for: JsonKey . Commerce. items, value: convertCommerceItemsToDictionary ( items) )
65
66
storeEventData ( type: EventType . updateCart, data: body)
66
67
}
67
68
68
- // Tracks an anonymous token registration event and store it locally
69
+ /// Tracks an anonymous token registration event and store it locally
69
70
public func trackAnonTokenRegistration( token: String ) {
70
71
var body = [ AnyHashable: Any] ( )
71
72
body. setValue ( for: JsonKey . token, value: token)
72
73
storeEventData ( type: EventType . tokenRegistration, data: body)
73
74
}
74
75
75
- // Stores an anonymous sessions locally. Updates the last session time each time when new session is created
76
+ /// Stores an anonymous sessions locally. Updates the last session time each time when new session is created
76
77
public func updateAnonSession( ) {
77
78
if var sessions = localStorage. anonymousSessions {
78
79
sessions. itbl_anon_sessions. totalAnonSessionCount += 1
@@ -86,14 +87,14 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
86
87
}
87
88
}
88
89
89
- // Syncs unsynced data which might have failed to sync when calling syncEvents for the first time after criterias met
90
+ /// Syncs unsynced data which might have failed to sync when calling syncEvents for the first time after criterias met
90
91
public func syncNonSyncedEvents( ) {
91
92
DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) { // little delay necessary in case it takes time to store userIdAnon in localstorage
92
93
self . syncEvents ( )
93
94
}
94
95
}
95
96
96
- // Syncs locally saved data through track APIs
97
+ /// Syncs locally saved data through track APIs
97
98
public func syncEvents( ) {
98
99
if let events = localStorage. anonymousUserEvents {
99
100
for var eventData in events {
@@ -144,26 +145,26 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
144
145
localStorage. anonymousUserUpdate = nil
145
146
}
146
147
147
- // Gets the anonymous criteria
148
+ /// Gets the anonymous criteria and updates the last criteria fetch time in milliseconds
148
149
public func getAnonCriteria( ) {
149
- lastCriteriaFetch = Date ( ) . timeIntervalSince1970 * 1000
150
+ updateLastCriteriaFetch ( currentTime : Date ( ) . timeIntervalSince1970 * 1000 )
150
151
151
152
IterableAPI . implementation? . getCriteriaData { returnedData in
152
153
self . localStorage. criteriaData = returnedData
153
154
} ;
154
155
}
155
156
156
- // Gets the last criteria fetch time in milliseconds
157
+ /// Gets the last criteria fetch time in milliseconds
157
158
public func getLastCriteriaFetch( ) -> Double {
158
159
return lastCriteriaFetch
159
160
}
160
161
161
- // Sets the last criteria fetch time in milliseconds
162
+ /// Sets the last criteria fetch time in milliseconds
162
163
public func updateLastCriteriaFetch( currentTime: Double ) {
163
164
lastCriteriaFetch = currentTime
164
165
}
165
166
166
- // Creates a user after criterias met and login the user and then sync the data through track APIs
167
+ /// Creates a user after criterias met and login the user and then sync the data through track APIs
167
168
private func createAnonymousUser( _ criteriaId: String ) {
168
169
var anonSessions = convertToDictionary ( data: localStorage. anonymousSessions? . itbl_anon_sessions)
169
170
let userId = IterableUtil . generateUUID ( )
@@ -195,7 +196,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
195
196
}
196
197
}
197
198
198
- // Checks if criterias are being met and returns criteriaId if it matches the criteria.
199
+ /// Checks if criterias are being met and returns criteriaId if it matches the criteria.
199
200
private func evaluateCriteriaAndReturnID( ) -> String ? {
200
201
guard let criteriaData = localStorage. criteriaData else { return nil }
201
202
@@ -214,7 +215,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
214
215
return CriteriaCompletionChecker ( anonymousCriteria: criteriaData, anonymousEvents: events) . getMatchedCriteria ( )
215
216
}
216
217
217
- // Stores event data locally
218
+ /// Stores event data locally
218
219
private func storeEventData( type: String , data: [ AnyHashable : Any ] , shouldOverWrite: Bool = false ) {
219
220
// Early return if no AUT consent was given
220
221
if !self . localStorage. anonymousUsageTrack {
@@ -233,7 +234,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
233
234
}
234
235
}
235
236
236
- // Stores User Update data
237
+ /// Stores User Update data
237
238
private func processAndStoreUserUpdate( data: [ AnyHashable : Any ] ) {
238
239
var userUpdate = localStorage. anonymousUserUpdate ?? [ : ]
239
240
@@ -246,7 +247,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
246
247
localStorage. anonymousUserUpdate = userUpdate
247
248
}
248
249
249
- // Stores all other event data
250
+ /// Stores all other event data
250
251
private func processAndStoreEvent( type: String , data: [ AnyHashable : Any ] ) {
251
252
var eventsDataObjects : [ [ AnyHashable : Any ] ] = localStorage. anonymousUserEvents ?? [ ]
252
253
0 commit comments