Skip to content

Commit

Permalink
feat: add alias api with previousId support
Browse files Browse the repository at this point in the history
  • Loading branch information
1abhishekpandey committed Nov 30, 2024
1 parent 92e80fd commit 7e375ca
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Sources/Classes/RSClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,32 @@ - (void)alias:(NSString *)newId {
[self reportDiscardedEvent];
return;
}
[self alias:newId options:nil];
[self alias:newId options:nil previousId:nil];
}

- (void) alias:(NSString *)newId options:(RSOption *) options {
[self alias:newId options:options previousId:nil];
}

- (void) alias:(NSString *)newId options:(RSOption *) options previousId:(NSString *)previousId {
if ([RSClient getOptStatus]) {
[self reportDiscardedEvent];
return;
}
RSContext *rc = [RSElementCache getContext];
NSMutableDictionary<NSString*,NSObject*>* traits = [rc.traits mutableCopy];

NSObject *prevId = [traits objectForKey:@"userId"];
if(prevId == nil) {
prevId =[traits objectForKey:@"id"];
}
if (prevId == nil) {
prevId = self.anonymousId;
NSObject *prevId = nil;
if (previousId != nil) {
prevId = previousId;
} else {
prevId = [traits objectForKey:@"userId"];
if(prevId == nil) {
prevId =[traits objectForKey:@"id"];
}
if (prevId == nil) {
prevId = self.anonymousId;
}
}

traits[@"id"] = newId;
Expand Down

0 comments on commit 7e375ca

Please sign in to comment.