Skip to content

Commit

Permalink
feat: add alias api with previousId support (#554)
Browse files Browse the repository at this point in the history
* chore: update podfile.lock

* fix: set previousId as anonmousId in alias API if userId is not present

* Revert "chore: update podfile.lock"

This reverts commit e96188c.

* feat: add alias api with previousId support

* feat: add new alias api in header file

* refactor: address comment

* fix: update Alias API by having previousId filed in the middle

* chore: fix alias api in RSClient.h
  • Loading branch information
1abhishekpandey authored Dec 9, 2024
1 parent b3b4a01 commit 6c68a3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Sources/Classes/Headers/Public/RSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef void (^Callback)(NSObject *_Nullable);
- (void) group:(NSString *)groupId traits:(NSDictionary<NSString*, id>*)traits;
- (void) group:(NSString *)groupId;

- (void) alias:(NSString *)newId previousId:(NSString * _Nullable)previousId options:(RSOption * _Nullable) options;
- (void) alias:(NSString *)newId options:(RSOption * _Nullable) options;
- (void) alias:(NSString *)newId;

Expand Down
8 changes: 6 additions & 2 deletions Sources/Classes/RSClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,22 @@ - (void)alias:(NSString *)newId {
[self reportDiscardedEvent];
return;
}
[self alias:newId options:nil];
[self alias:newId previousId:nil options:nil];
}

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

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

NSObject *prevId = [traits objectForKey:@"userId"] ?: [traits objectForKey:@"id"] ?: self.anonymousId;
NSObject *prevId = previousId ?: [traits objectForKey:@"userId"] ?: [traits objectForKey:@"id"] ?: self.anonymousId;

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

0 comments on commit 6c68a3d

Please sign in to comment.