From 6c68a3da2760be92573d493216a7cbcc23493dc0 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:28:33 +0530 Subject: [PATCH] feat: add alias api with previousId support (#554) * 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 e96188c7cc6777d4555365d2c92f57ea44d27cf0. * 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 --- Sources/Classes/Headers/Public/RSClient.h | 1 + Sources/Classes/RSClient.m | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/Classes/Headers/Public/RSClient.h b/Sources/Classes/Headers/Public/RSClient.h index 78d83535..a8ba8e5c 100644 --- a/Sources/Classes/Headers/Public/RSClient.h +++ b/Sources/Classes/Headers/Public/RSClient.h @@ -51,6 +51,7 @@ typedef void (^Callback)(NSObject *_Nullable); - (void) group:(NSString *)groupId traits:(NSDictionary*)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; diff --git a/Sources/Classes/RSClient.m b/Sources/Classes/RSClient.m index 3cc6a058..66831379 100644 --- a/Sources/Classes/RSClient.m +++ b/Sources/Classes/RSClient.m @@ -225,10 +225,14 @@ - (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; @@ -236,7 +240,7 @@ - (void) alias:(NSString *)newId options:(RSOption *) options { RSContext *rc = [RSElementCache getContext]; NSMutableDictionary* 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;