-
Notifications
You must be signed in to change notification settings - Fork 31
[MOB-11904] consent logging triggered in complete user login #937
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
base: feature/itbl-track-anon-user
Are you sure you want to change the base?
Conversation
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring
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; | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
🔹 Jira Ticket(s) if any
✏️ Description