Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-9402] update user should not be a separate call #453

Open
wants to merge 1 commit into
base: AUT_main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/anonymousUserTracking/anonymousUserEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
JSON.stringify(outputObject)
);
} catch (error) {
console.error('Error updating anonymous session:', error);

Check warning on line 89 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
}

Expand All @@ -98,7 +98,7 @@
validation: {}
})
.then((response) => {
const criteriaData: any = response.data;

Check warning on line 101 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
if (criteriaData) {
localStorage.setItem(
SHARED_PREFS_CRITERIA,
Expand All @@ -107,7 +107,7 @@
}
})
.catch((e) => {
console.log('response', e);

Check warning on line 110 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
});
}

Expand Down Expand Up @@ -162,7 +162,7 @@
return checker.getMatchedCriteria(criteriaData);
}
} catch (error) {
console.error('checkCriteriaCompletion', error);

Check warning on line 165 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}

return null;
Expand All @@ -170,6 +170,16 @@

private async createKnownUser(criteriaId: string) {
const userData = localStorage.getItem(SHARED_PREFS_ANON_SESSIONS);
const eventList = localStorage.getItem(SHARED_PREFS_EVENT_LIST_KEY);
const events = eventList ? JSON.parse(eventList) : [];

const dataFields = {
...events.find(
(event: any) => event[SHARED_PREFS_EVENT_TYPE] === UPDATE_USER

Check warning on line 178 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
)
};
delete dataFields[SHARED_PREFS_EVENT_TYPE];

const userId = uuidv4();

if (userData) {
Expand All @@ -179,7 +189,8 @@
user: {
userId,
mergeNestedObjects: true,
createNewFields: true
createNewFields: true,
dataFields
},
createdAt: this.getCurrentTime(),
deviceInfo: {
Expand All @@ -206,6 +217,15 @@
}
});
if (response?.status === 200) {
// Update local storage, remove updateUser from local storage
localStorage.setItem(
SHARED_PREFS_EVENT_LIST_KEY,
JSON.stringify(
events.filter(
(event: any) => event[SHARED_PREFS_EVENT_TYPE] !== UPDATE_USER

Check warning on line 225 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
)
)
);
if (anonUserIdSetter !== null) {
await anonUserIdSetter(userId);
}
Expand Down Expand Up @@ -276,7 +296,7 @@
if (shouldOverWrite) {
const trackingType = newDataObject[SHARED_PREFS_EVENT_TYPE];
const indexToUpdate = previousDataArray.findIndex(
(obj: any) => obj[SHARED_PREFS_EVENT_TYPE] === trackingType

Check warning on line 299 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
);
if (indexToUpdate !== -1) {
const dataToUpdate = previousDataArray[indexToUpdate];
Expand Down
Loading