Skip to content

Commit

Permalink
comment added
Browse files Browse the repository at this point in the history
  • Loading branch information
MoumitaM committed Apr 19, 2022
1 parent 8548d71 commit c35f609
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions utils/storage/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ class Storage {
if (Store.enabled) {
anonId = Store.get(anonymousIdKeyMap[key]);
}
// If anonymousId is not present in local storage and check cookie support exists
// fetch it from cookie
if (!anonId && Cookie.IsCookieSupported()) {
anonId = Cookie.get(anonymousIdKeyMap[key]);
}
Expand All @@ -295,26 +297,35 @@ class Storage {
* Finally if no anonymous Id is present in the source it will return undefined.
*
* anonymousIdOptions example:
*
* {
autoCapture: {
enabled: true,
source: "segment",
},
}
*
*/
getAnonymousId(anonymousIdOptions) {
// fetch the rl_anonymous_id from storage
const rlAnonymousId = this.parse(
this.decryptValue(this.storage.get(defaults.user_storage_anonymousId))
);
if (rlAnonymousId) {
return rlAnonymousId;
return rlAnonymousId; // return if already present
}
// validate the provided anonymousIdOptions argument
const source = get(anonymousIdOptions, "autoCapture.source");
if (
get(anonymousIdOptions, "autoCapture.enabled") === true &&
typeof source === "string"
) {
// fetch the anonymousId from the external source
// ex - segment
const anonId = this.fetchExternalAnonymousId(source);
if (anonId) return anonId;
if (anonId) return anonId; // return anonymousId if present
}

return rlAnonymousId;
return rlAnonymousId; // return undefined
}

/**
Expand Down

0 comments on commit c35f609

Please sign in to comment.