diff --git a/src/anonymousUserTracking/tests/userMergeScenarios.test.ts b/src/anonymousUserTracking/tests/userMergeScenarios.test.ts index 39eee7fb..88dcce04 100644 --- a/src/anonymousUserTracking/tests/userMergeScenarios.test.ts +++ b/src/anonymousUserTracking/tests/userMergeScenarios.test.ts @@ -135,9 +135,8 @@ describe('UserMergeScenariosTests', () => { const removeItemCalls = localStorageMock.removeItem.mock.calls.filter( (call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY ); - // count 1 means it did not remove item and so syncEvents was NOT called - // because removeItem gets called one time for the key in case of logout - expect(removeItemCalls.length).toBe(1); + // count 2 is because we want to remove the anon user and remove anon details + expect(removeItemCalls.length).toBe(2); const mergePostRequestData = mockRequest.history.post.find( (req) => req.url === ENDPOINT_MERGE_USER ); @@ -175,7 +174,6 @@ describe('UserMergeScenariosTests', () => { (call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY ); // count 2 means it removed items and so syncEvents was called - // because removeItem gets called one time for // the key in case of logout and 2nd time on syncevents expect(removeItemCalls.length).toBe(2); @@ -574,9 +572,8 @@ describe('UserMergeScenariosTests', () => { const removeItemCalls = localStorageMock.removeItem.mock.calls.filter( (call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY ); - // count 1 means it did not remove item and so syncEvents was NOT called - // because removeItem gets called one time for the key in case of logout - expect(removeItemCalls.length).toBe(1); + // count 2 is because we want to remove the anon user and remove anon details + expect(removeItemCalls.length).toBe(2); const mergePostRequestData = mockRequest.history.post.find( (req) => req.url === ENDPOINT_MERGE_USER ); diff --git a/src/authorization/authorization.ts b/src/authorization/authorization.ts index e07389b4..cc8d89e1 100644 --- a/src/authorization/authorization.ts +++ b/src/authorization/authorization.ts @@ -487,6 +487,8 @@ export function initialize( initializeEmailUser(email); if (replay) { syncEvents(); + } else { + anonUserManager.removeAnonSessionCriteriaData(); } return Promise.resolve(); } @@ -515,6 +517,8 @@ export function initialize( initializeUserId(userId); if (replay) { syncEvents(); + } else { + anonUserManager.removeAnonSessionCriteriaData(); } return Promise.resolve(); } @@ -865,6 +869,8 @@ export function initialize( initializeEmailUser(email); if (replay) { syncEvents(); + } else { + anonUserManager.removeAnonSessionCriteriaData(); } return token; } @@ -908,6 +914,8 @@ export function initialize( initializeUserId(userId); if (replay) { syncEvents(); + } else { + anonUserManager.removeAnonSessionCriteriaData(); } return token; }