-
Notifications
You must be signed in to change notification settings - Fork 32
[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
Changes from all commits
f71da94
ccec456
30f1d73
fe8ba35
ee468db
8ce9f8e
65e7e7a
bbcd698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -619,7 +619,27 @@ protected void registerDeviceToken(@Nullable String email, @Nullable String user | |
IterableLogger.e(TAG, "registerDeviceToken: applicationName is null, check that pushIntegrationName is set in IterableConfig"); | ||
} | ||
|
||
apiClient.registerDeviceToken(email, userId, authToken, applicationName, deviceToken, dataFields, deviceAttributes, _setUserSuccessCallbackHandler, _setUserFailureCallbackHandler); | ||
// Create a wrapper success handler that tracks consent before calling the original success handler | ||
IterableHelper.SuccessHandler wrappedSuccessHandler = getSuccessHandler(); | ||
|
||
apiClient.registerDeviceToken(email, userId, authToken, applicationName, deviceToken, dataFields, deviceAttributes, wrappedSuccessHandler, _setUserFailureCallbackHandler); | ||
} | ||
|
||
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; | ||
} | ||
//endregion | ||
|
||
|
@@ -825,6 +845,7 @@ public void setEmail(@Nullable String email, @Nullable String authToken, @Nullab | |
|
||
if (email == null) { | ||
unknownUserManager.setCriteriaMatched(false); | ||
setConsentLogged(false); | ||
} | ||
|
||
_setUserSuccessCallbackHandler = successHandler; | ||
|
@@ -893,6 +914,7 @@ public void setUserId(@Nullable String userId, @Nullable String authToken, @Null | |
|
||
if (userId == null) { | ||
unknownUserManager.setCriteriaMatched(false); | ||
setConsentLogged(false); | ||
} | ||
|
||
_setUserSuccessCallbackHandler = successHandler; | ||
|
@@ -919,10 +941,6 @@ private void attemptMergeAndEventReplay(@Nullable String emailOrUserId, boolean | |
|
||
if (replay && (_userId != null || _email != null)) { | ||
unknownUserManager.syncEventsAndUserUpdate(); | ||
|
||
if (_userIdUnknown == null) { | ||
trackConsentForUser(isEmail ? emailOrUserId : null, isEmail ? null : emailOrUserId, true); | ||
} | ||
} | ||
|
||
if (!isUnknown) { | ||
|
@@ -1484,6 +1502,41 @@ public boolean getVisitorUsageTracked() { | |
return sharedPreferences.getBoolean(IterableConstants.SHARED_PREFS_VISITOR_USAGE_TRACKED, false); | ||
} | ||
|
||
private boolean getConsentLogged() { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Good that we are persisting it now |
||
return sharedPreferences.getBoolean(IterableConstants.SHARED_PREFS_CONSENT_LOGGED, false); | ||
} | ||
|
||
private void setConsentLogged(boolean consentLogged) { | ||
if (_applicationContext == null) { | ||
return; | ||
} | ||
SharedPreferences sharedPref = _applicationContext.getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE); | ||
SharedPreferences.Editor editor = sharedPref.edit(); | ||
if (consentLogged) { | ||
editor.putBoolean(IterableConstants.SHARED_PREFS_CONSENT_LOGGED, true); | ||
} else { | ||
editor.remove(IterableConstants.SHARED_PREFS_CONSENT_LOGGED); | ||
} | ||
editor.apply(); | ||
} | ||
|
||
/** | ||
* Tracks consent during device registration if conditions are met. | ||
*/ | ||
private void trackConsentOnDeviceRegistration() { | ||
if (config.enableUnknownUserActivation && getVisitorUsageTracked() && config.identityResolution.getReplayOnVisitorToKnown()) { | ||
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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding consent to failure callback in a separate PR. |
||
} | ||
} | ||
} | ||
|
||
/** | ||
* Tracks user consent with the timestamp from when visitor usage was first tracked. | ||
* This should be called when transitioning from unknown to known user. | ||
|
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