Skip to content

Conversation

evantk91
Copy link
Contributor

@evantk91 evantk91 commented Aug 20, 2025

🔹 Jira Ticket(s) if any

✏️ Description

Please provide a brief description of what this pull request does.

@evantk91 evantk91 changed the title [MOB-11904] moves consent logging to complete user login [MOB-11904] consent logging triggered in complete user login Aug 20, 2025
@evantk91 evantk91 requested a review from Ayyanchira August 21, 2025 20:11
@evantk91 evantk91 requested a review from davidtruong August 22, 2025 21:08
Comment on lines 623 to 656
IterableHelper.SuccessHandler wrappedSuccessHandler = null;
if (_setUserSuccessCallbackHandler != null) {
final IterableHelper.SuccessHandler originalSuccessHandler = _setUserSuccessCallbackHandler;
wrappedSuccessHandler = new IterableHelper.SuccessHandler() {
@Override
public void onSuccess(@NonNull JSONObject data) {
// Track consent now that user has been created/updated via device registration
if (config.enableUnknownUserActivation && getVisitorUsageTracked() && config.identityResolution.getReplayOnVisitorToKnown()) {
if (!getConsentLogged()) {
boolean isUserKnown = (_userIdUnknown == null);
trackConsentForUser(_email, _userId, isUserKnown);
setConsentLogged(true);
}
}

// Call the original success handler
originalSuccessHandler.onSuccess(data);
}
};
} else if (config.enableUnknownUserActivation && getVisitorUsageTracked() && config.identityResolution.getReplayOnVisitorToKnown()) {
// Even if there's no original success handler, we still need to track consent
wrappedSuccessHandler = new IterableHelper.SuccessHandler() {
@Override
public void onSuccess(@NonNull JSONObject data) {
if (!getConsentLogged()) {
boolean isUserKnown = (_userIdUnknown == null);
trackConsentForUser(_email, _userId, isUserKnown);
setConsentLogged(true);
}
}
};
}

apiClient.registerDeviceToken(email, userId, authToken, applicationName, deviceToken, dataFields, deviceAttributes, wrappedSuccessHandler, _setUserFailureCallbackHandler);
Copy link
Member

Choose a reason for hiding this comment

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

Loved the idea of wrapping a success handler. It can be further optimized by not having repeated block of onSuccess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactoring

Evan Greer added 3 commits August 27, 2025 14:20
@evantk91 evantk91 requested a review from Ayyanchira August 27, 2025 21:24
Comment on lines +628 to 643
private IterableHelper.SuccessHandler getSuccessHandler() {
IterableHelper.SuccessHandler wrappedSuccessHandler = null;
if (_setUserSuccessCallbackHandler != null || (config.enableUnknownUserActivation && getVisitorUsageTracked() && config.identityResolution.getReplayOnVisitorToKnown())) {
final IterableHelper.SuccessHandler originalSuccessHandler = _setUserSuccessCallbackHandler;
wrappedSuccessHandler = data -> {
// Track consent now that user has been created/updated via device registration
trackConsentOnDeviceRegistration();

// Call the original success handler if it exists
if (originalSuccessHandler != null) {
originalSuccessHandler.onSuccess(data);
}
};
}
return wrappedSuccessHandler;
}
Copy link
Member

Choose a reason for hiding this comment

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

Good optimization

if (_applicationContext == null) {
return false;
}
SharedPreferences sharedPreferences = _applicationContext.getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Copy link
Member

Choose a reason for hiding this comment

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

Good that we are persisting it now

if (!getConsentLogged()) {
boolean isUserKnown = (_userIdUnknown == null);
trackConsentForUser(_email, _userId, isUserKnown);
setConsentLogged(true);
Copy link
Member

Choose a reason for hiding this comment

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

I saw that a user can be created even with device registration failing due to no device ID generation.
Do we not want consent to be tracked in that case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants