Skip to content
Open
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
12 changes: 6 additions & 6 deletions AdobeBranchExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ dependencies {
api project(path: ':AdobeBranchExtension')

// Adobe
implementation 'com.adobe.marketing.mobile:analytics:3.0.1'
implementation 'com.adobe.marketing.mobile:userprofile:3.0.0'
implementation 'com.adobe.marketing.mobile:core:3.2.0'
implementation 'com.adobe.marketing.mobile:lifecycle:3.0.1'
implementation 'com.adobe.marketing.mobile:identity:3.0.1'
implementation 'com.adobe.marketing.mobile:signal:3.0.0'
implementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
implementation 'com.adobe.marketing.mobile:core'

implementation("com.adobe.marketing.mobile:edge")
implementation("com.adobe.marketing.mobile:edgeidentity")
implementation("com.adobe.marketing.mobile:edgebridge")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
import android.app.Application;
import android.util.Log;

import com.adobe.marketing.mobile.Analytics;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.Identity;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Signal;
import com.adobe.marketing.mobile.UserProfile;
import com.adobe.marketing.mobile.edge.identity.AuthenticatedState;
import com.adobe.marketing.mobile.edge.identity.Identity;
import com.adobe.marketing.mobile.edge.identity.IdentityItem;
import com.adobe.marketing.mobile.edge.identity.IdentityMap;

import java.util.ArrayList;
import java.util.List;

import io.branch.adobe.extension.AdobeBranchExtension;
import io.branch.referral.Branch;
import io.branch.referral.BranchLogger;
import io.branch.referral.PrefHelper;

public class DemoApplication extends Application {
private static final String ADOBE_APP_ID = "d10f76259195/b0503e1a5dce/launch-9948a3b3a89d-development";
Expand All @@ -30,7 +28,18 @@ public void onCreate() {

Branch.enableLogging(BranchLogger.BranchLogLevel.VERBOSE);

Analytics.setVisitorIdentifier("custom_identifier_1234"); // to test custom visitor ID (key: "vid")
//Analytics.setVisitorIdentifier("custom_identifier_1234"); // to test custom visitor ID (key: "vid")
// Becomes ->

String namespace = "custom_namespace";
String customIdentifier = "custom_identifier_1234";

IdentityItem identityItem = new IdentityItem(customIdentifier);

IdentityMap identityMap = new IdentityMap();
identityMap.addItem(identityItem, namespace);

Identity.updateIdentities(identityMap);

// Initialize
initAdobeBranch();
Expand All @@ -52,12 +61,8 @@ private void initAdobeBranch() {
//AdobeBranchExtension.configureEventExclusionList(Arrays.asList("VIEW"));

List<Class<? extends Extension>> extensions = new ArrayList<>();
extensions.add(UserProfile.EXTENSION);
extensions.add(Analytics.EXTENSION);
extensions.add(Identity.EXTENSION);
extensions.add(Lifecycle.EXTENSION);
extensions.add(Signal.EXTENSION);
extensions.add(AdobeBranchExtension.EXTENSION);
extensions.add(Identity.EXTENSION);
MobileCore.registerExtensions(extensions, o -> {
Log.d(TAG, "AEP Mobile SDK is initialized");
});
Expand Down
19 changes: 12 additions & 7 deletions AdobeBranchExtension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,24 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'

// Branch
api 'io.branch.sdk.android:library:5.20.1'
api 'io.branch.sdk.android:library:5.20.3'
implementation ('com.google.android.gms:play-services-ads-identifier:18.0.1')
// for Huawei devices without GMS, adding it requires bumping up min api level to 19 though, so we
// leave it up to the client to add it following Branch documentation here: https://help.branch.io/developers-hub/docs/android-basic-integration
//implementation 'com.huawei.hms:ads-identifier:3.4.28.305'

// Adobe
androidTestImplementation 'com.adobe.marketing.mobile:analytics:3.0.2'
androidTestImplementation 'com.adobe.marketing.mobile:userprofile:3.0.1'
implementation 'com.adobe.marketing.mobile:core:3.5.0'
implementation 'com.adobe.marketing.mobile:lifecycle:3.0.2'
implementation 'com.adobe.marketing.mobile:identity:3.0.2'
implementation 'com.adobe.marketing.mobile:signal:3.0.1'
androidTestImplementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
androidTestImplementation("com.adobe.marketing.mobile:edge")
androidTestImplementation("com.adobe.marketing.mobile:edgeidentity")
androidTestImplementation("com.adobe.marketing.mobile:edgebridge")


implementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
implementation("com.adobe.marketing.mobile:edge")
implementation("com.adobe.marketing.mobile:edgeidentity")
implementation("com.adobe.marketing.mobile:edgebridge")


androidTestImplementation project(path: ':AdobeBranchExtension')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

import androidx.annotation.NonNull;

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionApi;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.SharedStateResolution;
import com.adobe.marketing.mobile.SharedStateResult;
import com.adobe.marketing.mobile.SharedStateStatus;
import com.adobe.marketing.mobile.edge.identity.Identity;
import com.adobe.marketing.mobile.edge.identity.IdentityItem;
import com.adobe.marketing.mobile.edge.identity.IdentityMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -29,7 +33,7 @@ public class AdobeBranchExtension extends Extension {
private static final String ADOBE_TRACK_EVENT = "com.adobe.eventType.generic.track";
private static final String ADOBE_EVENT_SOURCE = "com.adobe.eventSource.requestContent";

private static final String ADOBE_IDENTITY_EXTENSION = "com.adobe.module.identity";
private static final String ADOBE_IDENTITY_EXTENSION = "com.adobe.edge.identity";
private static final String ADOBE_ANALYTICS_EXTENSION = "com.adobe.module.analytics";

private static final String ADOBE_HUB_EVENT_TYPE = "com.adobe.eventType.hub";
Expand All @@ -41,9 +45,8 @@ public class AdobeBranchExtension extends Extension {

static final String CONFIGURATION_SHARED_STATE = "com.adobe.module.configuration";

static final String IDENTITY_ID = "mid";
static final String ANALYTICS_VISITOR_ID = "vid";
static final String ANALYTICS_TRACKING_ID = "aid";
String EXPERIENCE_CLOUD_ID_KEY = "ECID";

static AtomicBoolean PASSED_ADOBE_IDS_TO_BRANCH = new AtomicBoolean(false);

static List<String> allowList = new ArrayList<>();
Expand Down Expand Up @@ -99,6 +102,7 @@ public boolean readyForEvent(Event event) {
}

void handleAdobeEvent(final Event event) {
BranchLogger.v("handleAdobeEvent " + event);
BranchLogger.d(TAG + String.format("Started processing new event [%s] of type [%s] and source [%s]",
branchEventNameFromAdobeEvent(event), event.getType(), event.getSource()));

Expand All @@ -120,6 +124,7 @@ void handleAdobeEvent(final Event event) {
}

private boolean isTrackedEvent(final Event event) {
BranchLogger.v("isTrackedEvent apiWhitelist=" + apiWhitelist + " event.getType()=" + event.getSource());
if (apiWhitelist == null) {
return (event.getType().equals(ADOBE_TRACK_EVENT) && event.getSource().equals(ADOBE_EVENT_SOURCE));
}
Expand All @@ -134,10 +139,12 @@ private boolean isTrackedEvent(final Event event) {
}

private boolean isBranchConfigurationEvent(final Event event) {
BranchLogger.v("isBranchConfigurationEvent event.getType()=" + event.getType() + " event.getSource()=" + event.getSource());
return (event.getType().equals(BRANCH_CONFIGURATION_EVENT) && event.getSource().equals(BRANCH_EVENT_SOURCE));
}

private boolean isSharedStateEvent(final Event event) {
BranchLogger.v("isSharedStateEvent event.getType()=" + event.getType() + " event.getSource()=" + event.getSource());
return (event.getType().equals(ADOBE_HUB_EVENT_TYPE) && event.getSource().equals(ADOBE_SHARED_STATE_EVENT_SOURCE));
}

Expand All @@ -149,6 +156,7 @@ private boolean isSharedStateEvent(final Event event) {
*/
@SuppressWarnings("unchecked") // Cast Conversion to List<EventTypeSource>
private void handleBranchConfigurationEvent(final Event event) {
BranchLogger.v("handleBranchConfigurationEvent " + event);
Map<String, Object> eventData = event.getEventData();
if (eventData != null) {
BranchLogger.d(TAG + "Configuring AdobeBranch");
Expand Down Expand Up @@ -184,6 +192,7 @@ private void handleBranchConfigurationEvent(final Event event) {
* @param event Adobe Event
*/
private void handleSharedStateEvent(final Event event) {
BranchLogger.v("handleSharedStateEvent " + event);
Branch branch = Branch.getInstance();
if (branch != null && event != null && event.getEventData() != null) {
SharedStateResult extensionSharedState = null;
Expand All @@ -196,41 +205,43 @@ private void handleSharedStateEvent(final Event event) {
extensionSharedState = getApi().getSharedState(ADOBE_IDENTITY_EXTENSION, event, true, resolution);
}

if (extensionSharedState != null) {
for (Map.Entry<String, Object> entry : extensionSharedState.getValue().entrySet()) {
BranchLogger.d(String.format("identity extension shared state = %s", entry.toString()));

Object value = entry.getValue();
if (value == null) continue;
String valueAsString = value.toString();
if (TextUtils.isEmpty(valueAsString)) continue;

final String key = entry.getKey();
switch (key) {
case IDENTITY_ID:
// pass Adobe Experience Cloud ID (https://app.gitbook.com/@aep-sdks/s/docs/using-mobile-extensions/mobile-core/identity/identity-api-reference#getExperienceCloudIdTitle)
BranchLogger.d(TAG + "Setting Branch Request Metadata's $marketing_cloud_visitor_id to Adobe Experience Cloud ID: " + valueAsString);
branch.setRequestMetadata("$marketing_cloud_visitor_id", valueAsString);
break;
case ANALYTICS_VISITOR_ID:
// pass Adobe Custom Visitor ID (https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-analytics/analytics-api-reference#getvisitoridentifier)
BranchLogger.d(TAG + "Setting Branch Request Metadata's $analytics_visitor_id to Adobe Custom Visitor ID: " + valueAsString);
branch.setRequestMetadata("$analytics_visitor_id", valueAsString);
break;
case ANALYTICS_TRACKING_ID:
// pass Adobe Tracking ID (https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-analytics/analytics-api-reference#gettrackingidentifier)
// if MARKETING_CLOUD_VISITOR_ID is set this will always be null unless the Adobe Launch client set a grace period to support both IDs (https://docs.adobe.com/content/help/en/id-service/using/implementation/setup-analytics.html#:~:text=Grace%20periods%20can%20run%20for,a%20grace%20period%20if%20required.&text=You%20need%20a%20grace%20period,the%20same%20Analytics%20report%20suite.)
BranchLogger.d(TAG + "Setting Branch Request Metadata's $adobe_visitor_id to Adobe Tracking ID: " + valueAsString);
branch.setRequestMetadata("$adobe_visitor_id", valueAsString);
break;
BranchLogger.v("extensionSharedState " + extensionSharedState + " extensionSharedState.getStatus()=" + extensionSharedState.getStatus() + " extensionSharedState.getValue()=" + extensionSharedState.getValue());

Identity.getIdentities(new AdobeCallback<IdentityMap>() {
@Override
public void call(IdentityMap identityMap) {
if (identityMap == null) {
return;
}

List<String> namespaces = identityMap.getNamespaces();

for(int i = 0; i < namespaces.size(); i++){
List<IdentityItem> identities = identityMap.getIdentityItemsForNamespace(namespaces.get(i));
BranchLogger.v("Found namespace: " + namespaces.get(i));
for(int j = 0; j < identities.size(); j++){
BranchLogger.v("Found identity: " + identities.get(j).toString());

if(EXPERIENCE_CLOUD_ID_KEY.equals(namespaces.get(i))){
branch.setRequestMetadata("$marketing_cloud_visitor_id", identities.get(j).getId());
}
// Previously this id would be found with key "vid" but this has been removed.
// Now just iterate through map assuming 1 custom entry.
// TODO: Support the whole map?
else {
branch.setRequestMetadata("$analytics_visitor_id", identities.get(j).getId());
}

PASSED_ADOBE_IDS_TO_BRANCH.set(true);
}
}
if (IDENTITY_ID.equals(key) || ANALYTICS_VISITOR_ID.equals(key) || ANALYTICS_TRACKING_ID.equals(key)) {
// we received at least one, non-empty adobe id
PASSED_ADOBE_IDS_TO_BRANCH.set(true);

// By design this SDK stays locked until this is true
if(PASSED_ADOBE_IDS_TO_BRANCH.get()) {
Branch.getInstance().removeSessionInitializationDelay();
}
}
}
});
}
}

Expand All @@ -241,6 +252,7 @@ private void handleSharedStateEvent(final Event event) {
* @param event Adobe Event
*/
private void handleEvent(final Event event) {
BranchLogger.v("handleEvent" + event);
String name = branchEventNameFromAdobeEvent(event);
if (!isValidEventForBranch(name)) return;

Expand All @@ -259,6 +271,7 @@ private void handleEvent(final Event event) {
}

private BranchEvent branchEventFromAdobeEvent(final Event event) {
BranchLogger.v("branchEventFromAdobeEvent " + event);
BranchEvent branchEvent = null;
Map<String, Object> eventData = event.getEventData();
if (eventData != null) {
Expand Down