44
55import androidx .annotation .NonNull ;
66
7+ import com .adobe .marketing .mobile .AdobeCallback ;
78import com .adobe .marketing .mobile .Event ;
89import com .adobe .marketing .mobile .Extension ;
910import com .adobe .marketing .mobile .ExtensionApi ;
1011import com .adobe .marketing .mobile .MobileCore ;
1112import com .adobe .marketing .mobile .SharedStateResolution ;
1213import com .adobe .marketing .mobile .SharedStateResult ;
1314import 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 ;
1418import java .util .ArrayList ;
1519import java .util .List ;
1620import 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