Accessing response tokens

Personalization content returned from Adobe Target includes response tokens, which are details about the activity, offer, experience, user profile, geo information, and more. These details can be shared with third-party tools or used for debugging. Response tokens can be configured in the Adobe Target user interface.

To access any personalization content, provide a callback function when sending an event. This callback will be called after the SDK receives a successful response from the server. Your callback will be provided a result object, which may contain a propositions property containing any returned personalization content. Below is an example of providing a callback function.

alloy("sendEvent", {
    renderDecisions: true,
    xdm: {}
  }).then(function(result) {
    if (result.propositions) {
      // Manually render propositions
    }
  });

In this example, result.propositions, if it exists, is an array containing personalization propositions related to the event. Please see Rendering personalization content for more information on the content of result.propositions.

Assume you want to gather all activity names from all propositions that were automatically rendered by the web SDK and push them into a single array. You could then send the single array to a third party. In this case:

  1. Extract propositions from the result object.
  2. Loop through each proposition.
  3. Determine if the SDK rendered the proposition.
  4. If so, loop through each item in the proposition.
  5. Retrieve the activity name from the meta property, which is an object containing response tokens.
  6. Push the activity name into an array.
  7. Send the activity names to a third party.

Your code would look as follows:

alloy("sendEvent", {
    renderDecisions: true,
    xdm: {}
  }).then(function(result) {
    var activityNames = [];
    propositions.forEach(function(proposition) {
      if (proposition.renderAttempted) {
        proposition.items.forEach(function(item) {
          if (item.meta) {
            // item.meta contains the response tokens.
            var activityName = item.meta["activity.name"];
            // Ignore duplicates
            if (activityNames.indexOf(activityName) === -1) {
              activityNames.push(activityName);
            }
          }
        });
      }
    });
    // Now that activity names are in an array,
    // you can send them to a third party or use
    // them in some other way.
  });
recommendation-more-help
def05a9c-d048-422c-a3a1-88b2de863f4f