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

Add docs for internal APIs and some cleanup #26

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
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 @@ -155,7 +155,6 @@ static final class Audience {

// response keys
static final String VISITOR_PROFILE = "aamprofile";
static final String AUDIENCE_IDS = "audienceids";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not used

static final String UUID = "uuid";
//opted out response key
static final String OPTED_OUT_HIT_SENT = "optedouthitsent";
Expand Down Expand Up @@ -189,7 +188,6 @@ static final class Identity {
static final class VisitorID {

static final String ID = "ID";
static final String ID_ORIGIN = "ID_ORIGIN"; // todo: check this usage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this key was not read in 1.x either, when serializing the custom ids it uses
static final String VISITOR_ID_PARAMETER_KEY_CUSTOMER = "d_cid_ic";

static final String ID_TYPE = "ID_TYPE";
static final String STATE = "STATE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@
* <li>The Audience extension has a database to store impending network requests, which enables profile updates to
* still be collected and reported once the user's device comes back online.</li>
* </ol>
*
* The AudienceExtension listens for the following {@link Event}s:
* <ol>
* <li>{@link EventType#ANALYTICS} - {@link EventSource#RESPONSE_CONTENT}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_CONTENT}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_IDENTITY}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_RESET}</li>
* <li>{@link EventType#CONFIGURATION} - {@link EventSource#RESPONSE_CONTENT}</li>
* <li>{@link EventType#GENERIC_IDENTITY} - {@link EventSource#REQUEST_RESET}</li>
* <li>{@link EventType#LIFECYCLE} - {@link EventSource#RESPONSE_CONTENT}</li>
*</ol>
*
* The AudienceExtension dispatches the following {@code Event}s:
* <ol>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#RESPONSE_CONTENT}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#RESPONSE_IDENTITY}</li>
* </ol>
*/
public final class AudienceExtension extends Extension {

Expand Down Expand Up @@ -111,22 +94,22 @@ public void complete(final String responsePayload, final Event requestEvent) {
LOG_SOURCE,
"Not dispatching Audience hit response since resetIdentities API was called after queuing this hit."
);
resolveShareStateForEvent(requestEvent);
resolveSharedStateForEvent(requestEvent);
return;
}

Map<String, String> profile = new HashMap<>();

if (StringUtils.isNullOrEmpty(responsePayload)) {
Log.debug(LOG_TAG, LOG_SOURCE, "Null/empty response from server, nothing to process.");
resolveShareStateForEvent(requestEvent);
resolveSharedStateForEvent(requestEvent);
dispatchAudienceResponseContent(profile, requestEvent);
return;
}

// process the response from the AAM server and share the shared state
profile = processResponse(responsePayload, requestEvent);
resolveShareStateForEvent(requestEvent);
resolveSharedStateForEvent(requestEvent);

// if profile is empty, there was a json error in the response, don't dispatch a generic event
if (profile != null && !profile.isEmpty()) {
Expand Down Expand Up @@ -200,6 +183,18 @@ protected String getVersion() {
return com.adobe.marketing.mobile.Audience.extensionVersion();
}

/**
* The Audience extension listens for the following {@link Event}s:
* <ol>
* <li>{@link EventType#ANALYTICS} - {@link EventSource#RESPONSE_CONTENT}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_CONTENT}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_IDENTITY}</li>
* <li>{@link EventType#AUDIENCEMANAGER} - {@link EventSource#REQUEST_RESET}</li>
* <li>{@link EventType#CONFIGURATION} - {@link EventSource#RESPONSE_CONTENT}</li>
* <li>{@link EventType#GENERIC_IDENTITY} - {@link EventSource#REQUEST_RESET}</li>
* <li>{@link EventType#LIFECYCLE} - {@link EventSource#RESPONSE_CONTENT}</li>
*</ol>
*/
@Override
protected void onRegistered() {
getApi()
Expand Down Expand Up @@ -265,6 +260,15 @@ public boolean readyForEvent(@NonNull final Event event) {
//endregion

//region Event listeners

/**
* Processes the new configuration data from the Configuration Response events.
* If the {@link AudienceConstants.EventDataKeys.Configuration#GLOBAL_CONFIG_PRIVACY} value is
* {@code MobilePrivacyStatus#OPT_OUT} then we send out an opt-out hit to the Audience manager server,
* along with resetting the Audience Manager ids.
*
* @param event {@link Event} containing the Configuration event
*/
@VisibleForTesting
void handleConfigurationResponse(@NonNull final Event event) {
// check privacy status. if not found, .UNKNOWN privacy status will be used
Expand Down Expand Up @@ -305,6 +309,12 @@ void handleResetIdentities(@NonNull final Event event) {
shareStateForEvent(event);
}

/**
* Processes Analytics Response events containing the server response payload.
*
* @param event {@link Event} containing the Analytics event
* @see #processResponse(String, Event)
*/
private void handleAnalyticsResponse(@NonNull final Event event) {
if (!serverSideForwardingToAam(event)) {
Log.trace(
Expand Down Expand Up @@ -341,7 +351,8 @@ void handleAudienceRequestContent(@NonNull final Event event) {
}

/**
* Handles the getVisitorProfile API by dispatching a response content event containing the visitor profile stored in the {@link AudienceState}.
* Handles the getVisitorProfile API by dispatching a response event containing the visitor profile stored in the {@link AudienceState}.
* Dispatches events with {@link EventType#AUDIENCEMANAGER} - {@link EventSource#RESPONSE_IDENTITY}.
*
* @param event the event coming from the getVisitorProfile API invocation
*/
Expand All @@ -366,7 +377,7 @@ void handleAudienceRequestIdentity(@NonNull final Event event) {
}

/**
* Processes Lifecycle Response content and sends a signal to Audience Manager if aam forwarding is disabled.
* Processes Lifecycle Response content and sends a signal to Audience Manager if AAM forwarding is disabled.
*
* The Audience Manager shared state will be updated on Lifecycle Start events.
*
Expand Down Expand Up @@ -505,7 +516,7 @@ private void shareStateForEvent(final Event event) {
* Resolves the previously set pending shared state for the given event with current state data
* @param event the event for which to resolve the state
*/
private void resolveShareStateForEvent(final Event event) {
private void resolveSharedStateForEvent(final Event event) {
if (event == null) {
return;
}
Expand All @@ -519,6 +530,12 @@ private void resolveShareStateForEvent(final Event event) {
pendingSharedStates.remove(event.getUniqueIdentifier());
}

/**
* Extracts the {@link AudienceConstants.EventDataKeys.Configuration#ANALYTICS_CONFIG_AAMFORWARDING}
* key from config shared state and returns its status
* @param event current {@link Event} being processed
* @return true if server-side forwarding is enabled, false otherwise
*/
private boolean serverSideForwardingToAam(final Event event) {
final SharedStateResult configSharedState = getSharedStateForExtension(
AudienceConstants.EventDataKeys.Configuration.MODULE_NAME,
Expand Down Expand Up @@ -647,8 +664,8 @@ private void submitSignal(final Event event) {
}

/**
* Invokes the dispatcher passing the current visitor {@code profile} and {@code event} to dispatch {@code AUDIENCEMANAGER},
* {@code RESPONSE_CONTENT} event.
* Invokes the dispatcher passing the current visitor {@code profile} and {@code event} to dispatch the response for.
* Dispatches events with {@link EventType#AUDIENCEMANAGER} - {@link EventSource#RESPONSE_CONTENT}.
*
* @param profile {@code Map<String, String>} containing the user's profile
* @param event request {@link Event} object to be used for dispatching the paired response event;
Expand Down