Retrieve Target activities

Target mobile implementations use regional mboxes (now known as “scopes”) to deliver content from activities that use Target’s form-based Experience Composer. You need to update your mobile application to include scopes in your network calls.

The content returned by Target, also known as “offers”, typically consists of text or json which you need to consume in your application to render the final customer experience. Offers from Target are often used to:

  • Enable feature flags in your application
  • Serve alternate text or images

If you have activities which need to run in both Target extension and Offer Decisioning and Target extension versions of your application, be sure to test thoroughly. If you need to use different offers for different versions of your app, consider using the targeting options in the interface to deliver different offers to the different versions.

Always be sure to include error handling to display suitable experiences under error conditions.

Request and apply content on demand

IMPORTANT
After applying content to the app, it is imperative to fire displayed API to let Target know the visitor has seen the alternate or default content specified in the activity. Please see the Track Target conversion events page for more details.
Android example
tabs
Optimize SDK
code language-java

// Mboxes for Target activities
final DecisionScope decisionScope1 = DecisionScope("myTargetMbox1");
final DecisionScope decisionScope2 = new DecisionScope("myTargetMbox2");

final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);

// Prefetch the Target mboxes
Optimize.updatePropositions(decisionScopes,
                            new HashMap<String, Object>() {
                                {
                                    put("xdmKey", "xdmValue");
                                }
                            },
                            new HashMap<String, Object>() {
                                {
                                    put("dataKey", "dataValue");
                                }
                            },
                            new AdobeCallbackWithOptimizeError<Map<DecisionScope, OptimizeProposition>>() {
                                @Override
                                public void fail(AEPOptimizeError optimizeError) {
                                    // Log in case of error
                                    Log.d("Target Prefetch error", optimizeError.title);
                                }

                                @Override
                                public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
                                    // Retrieve cached propositions if prefetch succeeds
                                    Optimize.getPropositions(scopes, new AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>>() {
                                        @Override
                                      public void fail(final AdobeError adobeError) {
                                              // handle error
                                        }

                                        @Override
                                        public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
                                              if (propositionsMap != null && !propositionsMap.isEmpty()) {
                                                // get the propositions for the given decision scopes
                                                if (propositionsMap.contains(decisionScope1)) {
                                                      final OptimizeProposition proposition1 = propsMap.get(decisionScope1)
                                                      // read proposition1 offers and display them
                                                }
                                                if (propositionsMap.contains(decisionScope2)) {
                                                      final OptimizeProposition proposition2 = propsMap.get(decisionScope2)
                                                      // read proposition2 offers and display them
                                                }
                                              }
                                        }
                                      });
                                }
                            });
iOS example
tabs
Optimize SDK
code language-swift

// Mboxes for Target activities
let decisionScope1 = DecisionScope(name: "myTargetMbox1")
let decisionScope2 = DecisionScope(name: "myTargetMbox2")

// Prefetch the Target mboxes
Optimize.updatePropositions(for: [decisionScope1, decisionScope2]
                            withXdm: ["xdmKey": "xdmValue"]
                            andData: ["dataKey": "dataValue"]) { data, error in
            if let error = error as? AEPOptimizeError {
                // handle error
                return
            }
            // Retrieve cached propositions if prefetch succeeds
            Optimize.getPropositions(for: [decisionScope1, decisionScope2]) { propositionsDict, error in
                if let error = error {
                    // handle error
                    return
                }

                if let propositionsDict = propositionsDict {
                    // get the propositions for the given decision scopes

                    if let proposition1 = propositionsDict[decisionScope1] {
                        // read proposition1 offers and display them
                    }

                    if let proposition2 = propositionsDict[decisionScope2] {
                        // read proposition2 offers and display them
                    }
                }
            }
        }

Next, learn how to pass Target parameters using the Offer Decisioning and Target extension.

NOTE
We are committed to helping you be successful with your mobile Target migration from the Target extension to the Offer Decisioning and Target extension. If you run into obstacles with your migration or feel like there is critical information missing in this guide, please let us know by posting in this Community discussion.
recommendation-more-help
23093022-70e6-46bf-81c6-76f79c282c9c