Skip to content

Commit

Permalink
changed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
prabrisha-rudder authored and sayan-rudder committed Jan 13, 2020
1 parent 2ceeed6 commit adeae50
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ class Analytics {
? this.storage.getUserTraits()
: {};

this.anonymousId = this.storage.getAnonymousId()
? this.storage.getAnonymousId()
: generateUUID();

this.anonymousId = this.getAnonymousId();
this.storage.setUserId(this.userId);
this.storage.setAnonymousId(this.anonymousId);
this.eventRepository = EventRepository;
}

Expand Down Expand Up @@ -403,8 +399,7 @@ class Analytics {
processAndSendDataToDestinations(type, rudderElement, options, callback) {
try {
if (!this.anonymousId) {
this.anonymousId = generateUUID();
this.storage.setAnonymousId(this.anonymousId);
this.setAnonymousId();
}

rudderElement["message"]["context"]["traits"] = Object.assign(
Expand Down Expand Up @@ -498,17 +493,21 @@ class Analytics {
reset() {
this.userId = "";
this.userTraits = {};
this.anonymousId = "";
this.anonymousId = this.setAnonymousId();
this.storage.clear();
}

getAnonymousId(){
this.storage.getAnonymousId();
this.anonymousId = this.storage.getAnonymousId();
if(!this.anonymousId){
this.setAnonymousId();
}
return this.anonymousId;
}

setAnonymousId(anonymousId){
this.anonymousId = anonymousId;
this.storage.setAnonymousId(anonymousId);
this.anonymousId = anonymousId ? anonymousId : generateUUID();
this.storage.setAnonymousId(this.anonymousId);
}

/**
Expand Down

0 comments on commit adeae50

Please sign in to comment.