Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add alias api with previousId support #554

Merged
merged 11 commits into from
Dec 9, 2024

Conversation

1abhishekpandey
Copy link
Contributor

@1abhishekpandey 1abhishekpandey commented Nov 30, 2024

Description

  • Added an Alias API with previousId support. Now, previousId can be passed and will be preferred over the existing userId or anonymousId.
  • New Alias API:
- (void) alias:(NSString *)newId previousId:(NSString * _Nullable)previousId options:(RSOption * _Nullable) options;
  • This is to bring it in parity with the JS SDK so that previousId can be explicitly passed if needed.

NOTE: The change is backwards compatible, as we are introducing a new Alias API which adds a new behaviour to the existing payload schema.

How to test

Objective: We need to test, if previousId is passed then it should be used, else the existing behaviour should continue i.e., userId or anonymousId should be used.

  • Make an alias event and explicitly pass previousId field -> It should be set as the previousId.
  • Existing API: Make an Identify event, then RESET call and then an alias event (with previousId) -> previousId should be set as passed previousId.
  • Existing API: Make an alias event with only newId -> previousId should be set as anonymousId.
  • Existing API: Make an alias event with only newId and options -> previousId should be set as anonymousId.
  • Existing API: Make an identify event and then an alias event (without previousId) -> previousId should be set as previous userId.
  • Existing API: Make an Identify event, then RESET call and then an alias event (without previousId) -> previousId should be set as anonymousId.

@1abhishekpandey 1abhishekpandey self-assigned this Nov 30, 2024
@1abhishekpandey 1abhishekpandey marked this pull request as ready for review December 2, 2024 03:09
@1abhishekpandey 1abhishekpandey requested a review from a team as a code owner December 2, 2024 03:09
Comment on lines 243 to 253
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;
}
Copy link
Contributor

@SKannaniOS SKannaniOS Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify multiple if conditions, use the Ternary Conditional Operator (?:) as shown below.

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

SKannaniOS
SKannaniOS previously approved these changes Dec 2, 2024
ChryssaAliferi
ChryssaAliferi previously approved these changes Dec 6, 2024
Base automatically changed from fix/sdk-2669-ios-fix-alias-api to develop December 6, 2024 10:57
@1abhishekpandey 1abhishekpandey dismissed stale reviews from ChryssaAliferi and SKannaniOS December 6, 2024 10:57

The base branch was changed.

SKannaniOS
SKannaniOS previously approved these changes Dec 6, 2024
@1abhishekpandey 1abhishekpandey marked this pull request as draft December 9, 2024 07:20
@1abhishekpandey 1abhishekpandey marked this pull request as ready for review December 9, 2024 08:27
@SKannaniOS SKannaniOS merged commit 6c68a3d into develop Dec 9, 2024
13 of 14 checks passed
@1abhishekpandey 1abhishekpandey deleted the feat/sdk-2669-add-previousId-support-in-alias-api branch December 9, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants