Using response tokens

  1. Ensure that you are using Platform Web SDK version 2.6.0 (or later) or at.js version 1.1 (or later).

    For more information:

  2. In Target, click Administration > Response Tokens.

  3. Activate the desired response tokens, such as activity.id and offer.id.

    The following parameters are available by default:

    TypeParameterNotes
    Built-in Profilesprofile.activeActivitiesReturns an array of the activityIds the visitor is qualified for. It increments as users are qualified. For example, on a page with two Target requests delivering two different activities, the second request includes both activities.
    profile.isFirstSessionReturns “true” or “false.”
    profile.isNewSessionReturns “true” or “false.”
    profile.daysSinceLastVisitReturns the number of days since the visitor’s last visit.
    profile.tntIdReturns the visitor’s tntID
    profile.marketingCloudVisitorIdReturns the visitor’s Experience Cloud Visitor ID.
    profile.thirdPartyIdReturns the visitor’s third-party ID.
    profile.categoryAffinityReturns the visitor’s favorite category.
    profile.categoryAffinitiesReturns an array of the visitor’s top 5 categories as strings.
    Activityactivity.name
    activity.id
    experience.name
    experience.id
    offer.name
    offer.id
    Details of the current activity.
    Note that values for offer parameters are evaluated on the experience level.
    Geogeo.country
    geo.state
    geo.city
    geo.zip
    geo.dma
    geo.domainName
    geo.ispName
    geo.connectionSpeed
    geo.mobileCarrier
    See Geo for more information about using geo targeting in activities.
    Traffic Allocation Method
    (Applies to Auto-Target and Automated Personalization activities only.)
    experience.trafficAllocationIdReturns 0 if a visitor received an experience from being in “control” traffic and 1 if a visitor received an experience from the “targeted” traffic distribution.
    experience.trafficAllocationTypeReturn “control” or “targeted.”

    User profile attributes and Customer Attributes also display in the list.

    NOTE
    Parameters with special characters do not display in the list. Only alphanumeric characters and underscores are supported.
  4. (Conditional) To use a profile parameter as a response token, but the parameter has not been passed through a Target request and, thus, has not loaded into the Target UI, you can use the Add Response Token button to add the profile to the UI.

    Click Add Response Token, provide the token name, then click Activate.

  5. Create an activity.

Listen for responses and read response tokens

The process you use to listen for Target responses and read response tokens differs depending on whether you have a Platform Web SDK or at.js implementation.

Adobe Experience Platform Web SDK badge Platform Web SDK using the Handle object class

Use the Handle object class, which has a meta data object and a data object to listen for Target responses and read the response tokens.

The following response example adds a Platform Web SDK custom event handler directly to the HTML page (the table explains objects used in the code):

ObjectInformation
Type – Personalization.decisionWhether the decision was made by the Target or Offer Decisioning provider.
DecisionProvider – TGTTGT-Target. Target provides the response token metadata and values to the page.
MetaMetadata that is passed to the page.
DataValues of the metadata passed to the page.
<html>

<head>
 ...
 <script src="alloy.js"></script>
 <script>
  {
   "requestId": "4d0a7cfd-952c-408c-b3b8-438edc38250a",
   "handle": [{
    "type": "personalization:decisions",
    "payload": [{
     "id": "....",
     "scope": "__view__",
     "scopeDetails": {
      "decisionProvider": "TGT",
      "activity": {
       "id": "..."
      },
      "experience": {
       "id": "...."
      }
     },
     "items": [{
      "id": "123",
      "schema": "https://ns.adobe.com/personalization/dom-action",
      "meta": {
       "activity.id": "...",
       "activity.name": "...",
       "profile.foo": "...",
       "profile.bar": "..."
      },
      "data": {
       "id": "123",
       "type": "setHtml",
       "selector": "#foo",
       "prehidingSelector": "#foo",
       "content": "<div>Hello world</div>"
      }
     }]
    }]
   }]
  }
  });
 </script>
</head>

<body>
 ...
</body>

</html>

at.js badge at.js using custom events

Use at.js custom events to listen for the Target response and read the response tokens.

The following code sample adds an at.js custom event handler directly to the HTML page:

<html>
  <head>
    ....
    <script src="at.js"></script>
    <script>
      document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e) {
        console.log("Request succeeded", e.detail);
      });
    </script>
  <head>
  <body>
  ...
  </body>
</html>

Response token FAQs

Which role is required to activate or deactivate response tokens?

Response tokens can be activated or deactivated only by users with the Target Administrator role.

What happens if I am running Platform Web SDK 2.6.0 (or earlier)?

You do not have access to response tokens.

What happens if I am running at.js 1.0 (or earlier)?

You see the response tokens, but at.js cannot use them.

Can I have both Target Classic plugins and response tokens active at the same time?

Plugins and response tokens are available in parallel; however, plugins will be deprecated in the future.

Are response tokens delivered through all Target responses or only through Target responses delivering an activity?

Response tokens are delivered only through Target responses delivering an activity.

My Target Classic plugin included JavaScript. How do I replicate its functionality using response tokens?

When migrating to response tokens, this type of JavaScript must be kept in your codebase or tag management solution. You can trigger this code using Platform Web SDK or at.js custom events and pass the response token values to your JavaScript functions.

Why does my profile/Customer Attributes parameter not display in the response tokens list?

Target normally refreshes parameters every 15 minutes. This refresh depends on user action and data is refreshed only when you view the response tokens page. If your parameters do not display in the response token list, Target has not yet refreshed the data.

Also, if your parameter contains anything but non-alphanumeric characters or any symbol other than underscores, the parameter does not appear in the list. Currently, only alphanumeric and underscore characters are supported.

Does the response token still deliver content if it uses a deleted profile script or a profile parameter?

Response tokens extract information from user profiles and then deliver that information. If you delete a profile script or parameter, that does not mean that the information has been removed from the user profiles. The user profiles still have data corresponding to the profile script. The response token continues delivering the content. For users that do not have that information saved in their profiles, or for new visitors, that token is not delivered because the data is not present in their profiles.

Target does not toggle off the token automatically. If you delete a profile script and no longer want the token to be delivered, you must toggle off the token yourself.

I renamed my profile script, but why is the token using that script still active with the old name?

As mentioned above, response tokens work on the profile information saved for users. Even though you renamed your profile script, users who have visited your website have the old profile script value saved in their profiles. The token continues to pick up the old value that is already saved in the user profiles. If you now want to deliver content on the new name, you must toggle off the previous token and toggle on the new token.

If my attributes have changed, when are they be removed from the list?

Target performs a refresh of attributes at regular intervals. Any attribute that is not toggled on is removed during the next refresh. However, if you have an attribute that was toggled on and has been removed, that script is not removed from the attribute list until you toggle it off. As an example, you removed a profile script that was used as a token. Target removes only the toggled-off attributes from the list when they are deleted or renamed.

Send data to Google Analytics

The following sections describe how to send Target data to Google Analytics 4. Data sent by response tokens can also be sent to other other 3rd-party integrations.

AEP badge Sending data to Google Analytics via Platform Web SDK

Google Analytics can be sent data via Platform Web SDK version 2.6.0 (or later) by adding the following code in the HTML page.

NOTE
Make sure the response token key value pair are under the alloy("sendEvent" object.
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script type="text/javascript">
    alloy("sendEvent", {


    })
    .then(({ renderedPropositions, nonRenderedPropositions }) => {
        // concatenate all the propositions
        const propositions = [...renderedPropositions, ...nonRenderedPropositions];
        // extractResponseTokens() extract the meta from item -> meta
        const tokens = extractResponseTokens(propositions);
        const activityNames = [];
        const experienceNames = [];
        const uniqueTokens = distinct(tokens);


        uniqueTokens.forEach(token => {
            activityNames.push(token["activity.name"]);
            experienceNames.push(token["experience.name"]);
        });

        gtag('config', 'TAG_ID');
        gtag('event', 'action_name', {'eventCategory': 'target',
            'eventAction': experienceNames, 'eventLabel': activityNames
        });
    });
</script>

at.js badge Sending data to Google Analytics via at.js

Google Analytics can be sent data via at.js by adding the following code in the HTML page:

<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>

<script type="text/javascript">
    document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e) {
        var tokens = e.detail.responseTokens;

        if (isEmpty(tokens)) {
            return;
        }

        var activityNames = [];
        var experienceNames = [];
        var uniqueTokens = distinct(tokens);

        uniqueTokens.forEach(function(token) {
            activityNames.push(token["activity.name"]);
            experienceNames.push(token["experience.name"]);
        });

        gtag('config', 'TAG_ID');
        gtag('event', 'action_name', {'eventCategory': 'target',
            'eventAction': experienceNames, 'eventLabel': activityNames
        });
    });

    function isEmpty(val) {
        return (val === undefined || val == null || val.length <= 0) ? true : false;
    }

    function key(obj) {
        return Object.keys(obj)
        .map(function(k) { return k + "" + obj[k]; })
        .join("");
    }

    function distinct(arr) {
        var result = arr.reduce(function(acc, e) {
            acc[key(e)] = e;
            return acc;
        }, {});

        return Object.keys(result)
        .map(function(k) { return result[k]; });
    }
</script>

Debugging

The following sections provide information about debugging response tokens:

at.js badge Google Analytics and debugging

The following code lets you debug using Google Analytics:

<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>

<script type="text/javascript">
    document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e) {
      var tokens = e.detail.responseTokens;

      if (isEmpty(tokens)) {
        return;
      }

      var activityNames = [];
      var experienceNames = [];
      var uniqueTokens = distinct(tokens);

      uniqueTokens.forEach(function(token) {
        activityNames.push(token["activity.name"]);
        experienceNames.push(token["experience.name"]);
      });

      gtag('config', 'TAG_ID');
      gtag('event', 'action_name', {'eventCategory': 'target',
          'eventAction': experienceNames, 'eventLabel': activityNames
      });
    });

    function isEmpty(val) {
      return (val === undefined || val == null || val.length <= 0) ? true : false;
    }

    function key(obj) {
       return Object.keys(obj)
      .map(function(k) { return k + "" + obj[k]; })
      .join("");
    }

    function distinct(arr) {
      var result = arr.reduce(function(acc, e) {
        acc[key(e)] = e;
        return acc;
      }, {});

      return Object.keys(result)
      .map(function(k) { return result[k]; });
    }
</script>

Debugging using the equivalent of the ttMeta plugin

The equivalent of the ttMeta plugin for debugging purposes can be created by adding following code to HTML page:

<script type="text/javascript" >
  document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function (e) {
    window.ttMETA= typeof(window.ttMETA)!="undefined" ? window.ttMETA : [];

    var tokens=e.detail.responseTokens;

    if (isEmpty(tokens)) {
      return;
    }

    var uniqueTokens = distinct(tokens);

    uniqueTokens.forEach(function(token) {
      window.ttMETA.push({
        'CampaignName': token["activity.name"],
        'CampaignId' : token["activity.id"],
        'RecipeName': token["experience.name"],
        'RecipeId': token["experience.id"],
        'OfferId': token["offer.id"],
        'OfferName': token["offer.name"],
        'MboxName': e.detail.mbox});
      console.log(ttMETA);
    });
  });

  function isEmpty(val){
    return (val === undefined || val == null || val.length <= 0) ? true : false;
  }

  function key(obj) {
     return Object.keys(obj)
    .map(function(k) { return k + "" + obj[k]; })
    .join("");
  }

  function distinct(arr) {
    var result = arr.reduce(function(acc, e) {
      acc[key(e)] = e;
      return acc;
    }, {});

    return Object.keys(result)
    .map(function(k) { return result[k]; });
  }
</script>

at.js Training Video: Response Tokens and at.js Custom Events

The following video explains how to use response tokens and at.js custom events to share profile information from Target to 3rd-party systems.

NOTE
The Target Administration menu UI (formerly Setup) has been redesigned to provide improved performance, reduce the maintenance time required when releasing new features, and to improve the user experience across the product. The information in the following video is correct; however, options are in slightly different locations.
The video mentions option.name and option.id, which have been replaced with offer.name and offer.id, respectively.
video poster

Target


Adobe Target Maturity Webinar Series

Adobe Customer Success Webinars

Tuesday, Feb 4, 4:00 PM UTC

Adobe Target innovations, including GenAI, and best practices on AI-powered personalization and experimentation at scale.

Register