@@ -137,13 +137,6 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
137
137
let merge = identityResolution? . mergeOnAnonymousToKnown ?? config. identityResolution. mergeOnAnonymousToKnown
138
138
let replay = identityResolution? . replayOnVisitorToKnown ?? config. identityResolution. replayOnVisitorToKnown
139
139
140
- if ( config. enableAnonTracking) {
141
- if ( email != nil ) {
142
- attemptAndProcessMerge ( merge: merge ?? true , replay: replay ?? true , destinationUser: email, isEmail: true , failureHandler: failureHandler)
143
- }
144
- self . localStorage. userIdAnnon = nil
145
- }
146
-
147
140
if self . _email == email && email != nil {
148
141
self . checkAndUpdateAuthToken ( authToken)
149
142
return
@@ -158,6 +151,16 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
158
151
self . _email = email
159
152
self . _userId = nil
160
153
154
+ if config. enableAnonTracking, let email = email {
155
+ attemptAndProcessMerge (
156
+ merge: merge ?? true ,
157
+ replay: replay ?? true ,
158
+ destinationUser: email,
159
+ isEmail: true ,
160
+ failureHandler: failureHandler
161
+ )
162
+ self . localStorage. userIdAnnon = nil
163
+ }
161
164
self . _successCallback = successHandler
162
165
self . _failureCallback = failureHandler
163
166
self . storeIdentifierData ( )
@@ -171,16 +174,6 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
171
174
let merge = identityResolution? . mergeOnAnonymousToKnown ?? config. identityResolution. mergeOnAnonymousToKnown
172
175
let replay = identityResolution? . replayOnVisitorToKnown ?? config. identityResolution. replayOnVisitorToKnown
173
176
174
- if ( config. enableAnonTracking) {
175
- if ( userId != nil && userId != localStorage. userIdAnnon) {
176
- attemptAndProcessMerge ( merge: merge ?? true , replay: replay ?? true , destinationUser: userId, isEmail: false , failureHandler: failureHandler)
177
- }
178
-
179
- if ( !isAnon) {
180
- self . localStorage. userIdAnnon = nil
181
- }
182
- }
183
-
184
177
if self . _userId == userId && userId != nil {
185
178
self . checkAndUpdateAuthToken ( authToken)
186
179
return
@@ -195,6 +188,22 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
195
188
self . _email = nil
196
189
self . _userId = userId
197
190
191
+ if config. enableAnonTracking {
192
+ if let userId = userId, userId != localStorage. userIdAnnon {
193
+ attemptAndProcessMerge (
194
+ merge: merge ?? true ,
195
+ replay: replay ?? true ,
196
+ destinationUser: userId,
197
+ isEmail: false ,
198
+ failureHandler: failureHandler
199
+ )
200
+ }
201
+
202
+ if !isAnon {
203
+ localStorage. userIdAnnon = nil
204
+ }
205
+ }
206
+
198
207
self . _successCallback = successHandler
199
208
self . _failureCallback = failureHandler
200
209
self . storeIdentifierData ( )
@@ -210,7 +219,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
210
219
211
220
if mergeResult == MergeResult . mergenotrequired || mergeResult == MergeResult . mergesuccessful {
212
221
if ( replay) {
213
- self . anonymousUserManager. syncNonSyncedEvents ( )
222
+ self . anonymousUserManager. syncEvents ( )
214
223
}
215
224
} else {
216
225
failureHandler ? ( error, nil )
0 commit comments