Skip to content

Commit 241946b

Browse files
Migrate to Edge Bridge library
1 parent 52bcbba commit 241946b

File tree

4 files changed

+83
-60
lines changed

4 files changed

+83
-60
lines changed

AdobeBranchExample/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ dependencies {
3939
api project(path: ':AdobeBranchExtension')
4040

4141
// Adobe
42-
implementation 'com.adobe.marketing.mobile:analytics:3.0.1'
43-
implementation 'com.adobe.marketing.mobile:userprofile:3.0.0'
44-
implementation 'com.adobe.marketing.mobile:core:3.2.0'
45-
implementation 'com.adobe.marketing.mobile:lifecycle:3.0.1'
46-
implementation 'com.adobe.marketing.mobile:identity:3.0.1'
47-
implementation 'com.adobe.marketing.mobile:signal:3.0.0'
42+
implementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
43+
implementation 'com.adobe.marketing.mobile:core'
44+
45+
implementation("com.adobe.marketing.mobile:edge")
46+
implementation("com.adobe.marketing.mobile:edgeidentity")
47+
implementation("com.adobe.marketing.mobile:edgebridge")
4848
}

AdobeBranchExample/src/main/java/io/branch/adobe/demo/DemoApplication.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
import android.app.Application;
44
import android.util.Log;
55

6-
import com.adobe.marketing.mobile.Analytics;
76
import com.adobe.marketing.mobile.Extension;
8-
import com.adobe.marketing.mobile.Identity;
9-
import com.adobe.marketing.mobile.Lifecycle;
107
import com.adobe.marketing.mobile.LoggingMode;
118
import com.adobe.marketing.mobile.MobileCore;
12-
import com.adobe.marketing.mobile.Signal;
13-
import com.adobe.marketing.mobile.UserProfile;
9+
import com.adobe.marketing.mobile.edge.identity.AuthenticatedState;
10+
import com.adobe.marketing.mobile.edge.identity.Identity;
11+
import com.adobe.marketing.mobile.edge.identity.IdentityItem;
12+
import com.adobe.marketing.mobile.edge.identity.IdentityMap;
1413

1514
import java.util.ArrayList;
1615
import java.util.List;
1716

1817
import io.branch.adobe.extension.AdobeBranchExtension;
1918
import io.branch.referral.Branch;
2019
import io.branch.referral.BranchLogger;
21-
import io.branch.referral.PrefHelper;
2220

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

3129
Branch.enableLogging(BranchLogger.BranchLogLevel.VERBOSE);
3230

33-
Analytics.setVisitorIdentifier("custom_identifier_1234"); // to test custom visitor ID (key: "vid")
31+
//Analytics.setVisitorIdentifier("custom_identifier_1234"); // to test custom visitor ID (key: "vid")
32+
// Becomes ->
33+
34+
String namespace = "custom_namespace";
35+
String customIdentifier = "custom_identifier_1234";
36+
37+
IdentityItem identityItem = new IdentityItem(customIdentifier);
38+
39+
IdentityMap identityMap = new IdentityMap();
40+
identityMap.addItem(identityItem, namespace);
41+
42+
Identity.updateIdentities(identityMap);
3443

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

5463
List<Class<? extends Extension>> extensions = new ArrayList<>();
55-
extensions.add(UserProfile.EXTENSION);
56-
extensions.add(Analytics.EXTENSION);
57-
extensions.add(Identity.EXTENSION);
58-
extensions.add(Lifecycle.EXTENSION);
59-
extensions.add(Signal.EXTENSION);
6064
extensions.add(AdobeBranchExtension.EXTENSION);
65+
extensions.add(Identity.EXTENSION);
6166
MobileCore.registerExtensions(extensions, o -> {
6267
Log.d(TAG, "AEP Mobile SDK is initialized");
6368
});

AdobeBranchExtension/build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,24 @@ dependencies {
7171
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
7272

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

8080
// Adobe
81-
androidTestImplementation 'com.adobe.marketing.mobile:analytics:3.0.2'
82-
androidTestImplementation 'com.adobe.marketing.mobile:userprofile:3.0.1'
83-
implementation 'com.adobe.marketing.mobile:core:3.5.0'
84-
implementation 'com.adobe.marketing.mobile:lifecycle:3.0.2'
85-
implementation 'com.adobe.marketing.mobile:identity:3.0.2'
86-
implementation 'com.adobe.marketing.mobile:signal:3.0.1'
81+
androidTestImplementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
82+
androidTestImplementation("com.adobe.marketing.mobile:edge")
83+
androidTestImplementation("com.adobe.marketing.mobile:edgeidentity")
84+
androidTestImplementation("com.adobe.marketing.mobile:edgebridge")
85+
86+
87+
implementation platform('com.adobe.marketing.mobile:sdk-bom:3.15.0')
88+
implementation("com.adobe.marketing.mobile:edge")
89+
implementation("com.adobe.marketing.mobile:edgeidentity")
90+
implementation("com.adobe.marketing.mobile:edgebridge")
91+
8792

8893
androidTestImplementation project(path: ':AdobeBranchExtension')
8994
}

AdobeBranchExtension/src/main/java/io/branch/adobe/extension/AdobeBranchExtension.java

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
import androidx.annotation.NonNull;
66

7+
import com.adobe.marketing.mobile.AdobeCallback;
78
import com.adobe.marketing.mobile.Event;
89
import com.adobe.marketing.mobile.Extension;
910
import com.adobe.marketing.mobile.ExtensionApi;
1011
import com.adobe.marketing.mobile.MobileCore;
1112
import com.adobe.marketing.mobile.SharedStateResolution;
1213
import com.adobe.marketing.mobile.SharedStateResult;
1314
import com.adobe.marketing.mobile.SharedStateStatus;
15+
import com.adobe.marketing.mobile.edge.identity.Identity;
16+
import com.adobe.marketing.mobile.edge.identity.IdentityItem;
17+
import com.adobe.marketing.mobile.edge.identity.IdentityMap;
1418
import java.util.ArrayList;
1519
import java.util.List;
1620
import java.util.Map;
@@ -29,7 +33,7 @@ public class AdobeBranchExtension extends Extension {
2933
private static final String ADOBE_TRACK_EVENT = "com.adobe.eventType.generic.track";
3034
private static final String ADOBE_EVENT_SOURCE = "com.adobe.eventSource.requestContent";
3135

32-
private static final String ADOBE_IDENTITY_EXTENSION = "com.adobe.module.identity";
36+
private static final String ADOBE_IDENTITY_EXTENSION = "com.adobe.edge.identity";
3337
private static final String ADOBE_ANALYTICS_EXTENSION = "com.adobe.module.analytics";
3438

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

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

44-
static final String IDENTITY_ID = "mid";
45-
static final String ANALYTICS_VISITOR_ID = "vid";
46-
static final String ANALYTICS_TRACKING_ID = "aid";
48+
String EXPERIENCE_CLOUD_ID_KEY = "ECID";
49+
4750
static AtomicBoolean PASSED_ADOBE_IDS_TO_BRANCH = new AtomicBoolean(false);
4851

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

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

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

122126
private boolean isTrackedEvent(final Event event) {
127+
BranchLogger.v("isTrackedEvent apiWhitelist=" + apiWhitelist + " event.getType()=" + event.getSource());
123128
if (apiWhitelist == null) {
124129
return (event.getType().equals(ADOBE_TRACK_EVENT) && event.getSource().equals(ADOBE_EVENT_SOURCE));
125130
}
@@ -134,10 +139,12 @@ private boolean isTrackedEvent(final Event event) {
134139
}
135140

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

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

@@ -149,6 +156,7 @@ private boolean isSharedStateEvent(final Event event) {
149156
*/
150157
@SuppressWarnings("unchecked") // Cast Conversion to List<EventTypeSource>
151158
private void handleBranchConfigurationEvent(final Event event) {
159+
BranchLogger.v("handleBranchConfigurationEvent " + event);
152160
Map<String, Object> eventData = event.getEventData();
153161
if (eventData != null) {
154162
BranchLogger.d(TAG + "Configuring AdobeBranch");
@@ -184,6 +192,7 @@ private void handleBranchConfigurationEvent(final Event event) {
184192
* @param event Adobe Event
185193
*/
186194
private void handleSharedStateEvent(final Event event) {
195+
BranchLogger.v("handleSharedStateEvent " + event);
187196
Branch branch = Branch.getInstance();
188197
if (branch != null && event != null && event.getEventData() != null) {
189198
SharedStateResult extensionSharedState = null;
@@ -196,41 +205,43 @@ private void handleSharedStateEvent(final Event event) {
196205
extensionSharedState = getApi().getSharedState(ADOBE_IDENTITY_EXTENSION, event, true, resolution);
197206
}
198207

199-
if (extensionSharedState != null) {
200-
for (Map.Entry<String, Object> entry : extensionSharedState.getValue().entrySet()) {
201-
BranchLogger.d(String.format("identity extension shared state = %s", entry.toString()));
202-
203-
Object value = entry.getValue();
204-
if (value == null) continue;
205-
String valueAsString = value.toString();
206-
if (TextUtils.isEmpty(valueAsString)) continue;
207-
208-
final String key = entry.getKey();
209-
switch (key) {
210-
case IDENTITY_ID:
211-
// pass Adobe Experience Cloud ID (https://app.gitbook.com/@aep-sdks/s/docs/using-mobile-extensions/mobile-core/identity/identity-api-reference#getExperienceCloudIdTitle)
212-
BranchLogger.d(TAG + "Setting Branch Request Metadata's $marketing_cloud_visitor_id to Adobe Experience Cloud ID: " + valueAsString);
213-
branch.setRequestMetadata("$marketing_cloud_visitor_id", valueAsString);
214-
break;
215-
case ANALYTICS_VISITOR_ID:
216-
// pass Adobe Custom Visitor ID (https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-analytics/analytics-api-reference#getvisitoridentifier)
217-
BranchLogger.d(TAG + "Setting Branch Request Metadata's $analytics_visitor_id to Adobe Custom Visitor ID: " + valueAsString);
218-
branch.setRequestMetadata("$analytics_visitor_id", valueAsString);
219-
break;
220-
case ANALYTICS_TRACKING_ID:
221-
// pass Adobe Tracking ID (https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-analytics/analytics-api-reference#gettrackingidentifier)
222-
// 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.)
223-
BranchLogger.d(TAG + "Setting Branch Request Metadata's $adobe_visitor_id to Adobe Tracking ID: " + valueAsString);
224-
branch.setRequestMetadata("$adobe_visitor_id", valueAsString);
225-
break;
208+
BranchLogger.v("extensionSharedState " + extensionSharedState + " extensionSharedState.getStatus()=" + extensionSharedState.getStatus() + " extensionSharedState.getValue()=" + extensionSharedState.getValue());
209+
210+
Identity.getIdentities(new AdobeCallback<IdentityMap>() {
211+
@Override
212+
public void call(IdentityMap identityMap) {
213+
if (identityMap == null) {
214+
return;
215+
}
216+
217+
List<String> namespaces = identityMap.getNamespaces();
218+
219+
for(int i = 0; i < namespaces.size(); i++){
220+
List<IdentityItem> identities = identityMap.getIdentityItemsForNamespace(namespaces.get(i));
221+
BranchLogger.v("Found namespace: " + namespaces.get(i));
222+
for(int j = 0; j < identities.size(); j++){
223+
BranchLogger.v("Found identity: " + identities.get(j).toString());
224+
225+
if(EXPERIENCE_CLOUD_ID_KEY.equals(namespaces.get(i))){
226+
branch.setRequestMetadata("$marketing_cloud_visitor_id", identities.get(j).getId());
227+
}
228+
// Previously this id would be found with key "vid" but this has been removed.
229+
// Now just iterate through map assuming 1 custom entry.
230+
// TODO: Support the whole map?
231+
else {
232+
branch.setRequestMetadata("$analytics_visitor_id", identities.get(j).getId());
233+
}
234+
235+
PASSED_ADOBE_IDS_TO_BRANCH.set(true);
236+
}
226237
}
227-
if (IDENTITY_ID.equals(key) || ANALYTICS_VISITOR_ID.equals(key) || ANALYTICS_TRACKING_ID.equals(key)) {
228-
// we received at least one, non-empty adobe id
229-
PASSED_ADOBE_IDS_TO_BRANCH.set(true);
238+
239+
// By design this SDK stays locked until this is true
240+
if(PASSED_ADOBE_IDS_TO_BRANCH.get()) {
230241
Branch.getInstance().removeSessionInitializationDelay();
231242
}
232243
}
233-
}
244+
});
234245
}
235246
}
236247

@@ -241,6 +252,7 @@ private void handleSharedStateEvent(final Event event) {
241252
* @param event Adobe Event
242253
*/
243254
private void handleEvent(final Event event) {
255+
BranchLogger.v("handleEvent" + event);
244256
String name = branchEventNameFromAdobeEvent(event);
245257
if (!isValidEventForBranch(name)) return;
246258

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

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

0 commit comments

Comments
 (0)