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 #485

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,11 @@ void alias(@NonNull RudderMessage message) {
* @param newId New userId for the user
*/
public void alias(String newId) {
alias(newId, null);
alias(newId, null, null);
}

public void alias(@NonNull String newId, @Nullable RudderOption option) {
alias(newId, option, null);
}

/**
Expand All @@ -478,7 +482,7 @@ public void alias(String newId) {
* @param newId New userId for the user
* @param option RudderOptions for this event
*/
public void alias(@NonNull String newId, @Nullable RudderOption option) {
public void alias(@NonNull String newId, @Nullable RudderOption option, @Nullable String previousId) {
RudderContext context = getRudderContext();
Map<String, Object> traits = null;
if (context != null) {
Expand All @@ -488,12 +492,16 @@ public void alias(@NonNull String newId, @Nullable RudderOption option) {
return;
String prevUserId = null;

if (traits.containsKey("userId")) {
prevUserId = (String) traits.get("userId");
} else if (traits.containsKey("id")) {
prevUserId = (String) traits.get("id");
if (previousId != null) {
prevUserId = previousId;
} else {
prevUserId = RudderContext.getAnonymousId();
if (traits.containsKey("userId")) {
prevUserId = (String) traits.get("userId");
} else if (traits.containsKey("id")) {
prevUserId = (String) traits.get("id");
} else {
prevUserId = RudderContext.getAnonymousId();
}
}

traits.put("userId", newId);
Expand Down
Loading