@@ -29,7 +29,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
2929 private var config : IterableConfig
3030 private( set) var lastCriteriaFetch : Double = 0
3131
32- // Tracks an anonymous event and store it locally
32+ /// Tracks an anonymous event and store it locally
3333 public func trackAnonEvent( name: String , dataFields: [ AnyHashable : Any ] ? ) {
3434 var body = [ AnyHashable: Any] ( )
3535 body. setValue ( for: JsonKey . eventName, value: name)
@@ -41,11 +41,12 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
4141 storeEventData ( type: EventType . customEvent, data: body)
4242 }
4343
44+ /// Tracks an anonymous user update event and store it locally
4445 public func trackAnonUpdateUser( _ dataFields: [ AnyHashable : Any ] ) {
4546 storeEventData ( type: EventType . updateUser, data: dataFields, shouldOverWrite: true )
4647 }
4748
48- // Tracks an anonymous purchase event and store it locally
49+ /// Tracks an anonymous purchase event and store it locally
4950 public func trackAnonPurchaseEvent( total: NSNumber , items: [ CommerceItem ] , dataFields: [ AnyHashable : Any ] ? ) {
5051 var body = [ AnyHashable: Any] ( )
5152 body. setValue ( for: JsonKey . Body. createdAt, value: IterableUtil . secondsFromEpoch ( for: dateProvider. currentDate) )
@@ -57,22 +58,22 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
5758 storeEventData ( type: EventType . purchase, data: body)
5859 }
5960
60- // Tracks an anonymous cart event and store it locally
61+ /// Tracks an anonymous cart event and store it locally
6162 public func trackAnonUpdateCart( items: [ CommerceItem ] ) {
6263 var body = [ AnyHashable: Any] ( )
6364 body. setValue ( for: JsonKey . Body. createdAt, value: IterableUtil . secondsFromEpoch ( for: dateProvider. currentDate) )
6465 body. setValue ( for: JsonKey . Commerce. items, value: convertCommerceItemsToDictionary ( items) )
6566 storeEventData ( type: EventType . updateCart, data: body)
6667 }
6768
68- // Tracks an anonymous token registration event and store it locally
69+ /// Tracks an anonymous token registration event and store it locally
6970 public func trackAnonTokenRegistration( token: String ) {
7071 var body = [ AnyHashable: Any] ( )
7172 body. setValue ( for: JsonKey . token, value: token)
7273 storeEventData ( type: EventType . tokenRegistration, data: body)
7374 }
7475
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
7677 public func updateAnonSession( ) {
7778 if var sessions = localStorage. anonymousSessions {
7879 sessions. itbl_anon_sessions. totalAnonSessionCount += 1
@@ -86,14 +87,14 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
8687 }
8788 }
8889
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
9091 public func syncNonSyncedEvents( ) {
9192 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) { // little delay necessary in case it takes time to store userIdAnon in localstorage
9293 self . syncEvents ( )
9394 }
9495 }
9596
96- // Syncs locally saved data through track APIs
97+ /// Syncs locally saved data through track APIs
9798 public func syncEvents( ) {
9899 if let events = localStorage. anonymousUserEvents {
99100 for var eventData in events {
@@ -144,26 +145,26 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
144145 localStorage. anonymousUserUpdate = nil
145146 }
146147
147- // Gets the anonymous criteria
148+ /// Gets the anonymous criteria and updates the last criteria fetch time in milliseconds
148149 public func getAnonCriteria( ) {
149- lastCriteriaFetch = Date ( ) . timeIntervalSince1970 * 1000
150+ updateLastCriteriaFetch ( currentTime : Date ( ) . timeIntervalSince1970 * 1000 )
150151
151152 IterableAPI . implementation? . getCriteriaData { returnedData in
152153 self . localStorage. criteriaData = returnedData
153154 } ;
154155 }
155156
156- // Gets the last criteria fetch time in milliseconds
157+ /// Gets the last criteria fetch time in milliseconds
157158 public func getLastCriteriaFetch( ) -> Double {
158159 return lastCriteriaFetch
159160 }
160161
161- // Sets the last criteria fetch time in milliseconds
162+ /// Sets the last criteria fetch time in milliseconds
162163 public func updateLastCriteriaFetch( currentTime: Double ) {
163164 lastCriteriaFetch = currentTime
164165 }
165166
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
167168 private func createAnonymousUser( _ criteriaId: String ) {
168169 var anonSessions = convertToDictionary ( data: localStorage. anonymousSessions? . itbl_anon_sessions)
169170 let userId = IterableUtil . generateUUID ( )
@@ -195,7 +196,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
195196 }
196197 }
197198
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.
199200 private func evaluateCriteriaAndReturnID( ) -> String ? {
200201 guard let criteriaData = localStorage. criteriaData else { return nil }
201202
@@ -214,7 +215,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
214215 return CriteriaCompletionChecker ( anonymousCriteria: criteriaData, anonymousEvents: events) . getMatchedCriteria ( )
215216 }
216217
217- // Stores event data locally
218+ /// Stores event data locally
218219 private func storeEventData( type: String , data: [ AnyHashable : Any ] , shouldOverWrite: Bool = false ) {
219220 // Early return if no AUT consent was given
220221 if !self . localStorage. anonymousUsageTrack {
@@ -233,7 +234,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
233234 }
234235 }
235236
236- // Stores User Update data
237+ /// Stores User Update data
237238 private func processAndStoreUserUpdate( data: [ AnyHashable : Any ] ) {
238239 var userUpdate = localStorage. anonymousUserUpdate ?? [ : ]
239240
@@ -246,7 +247,7 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
246247 localStorage. anonymousUserUpdate = userUpdate
247248 }
248249
249- // Stores all other event data
250+ /// Stores all other event data
250251 private func processAndStoreEvent( type: String , data: [ AnyHashable : Any ] ) {
251252 var eventsDataObjects : [ [ AnyHashable : Any ] ] = localStorage. anonymousUserEvents ?? [ ]
252253
0 commit comments