Sunday, July 7, 2019

How to access All activity names running on a page using custom Javascript code in Adobe Target?

custom javascript in adobe target

How to access All activity names or other values from response token running on a page using Javascript in Adobe Target?

There are some use cases which you would like to configure in Adobe Target where you might need to access all the activity names running on a page and use that information accordingly to target customer.

Following Javascript snippet would help you access information available in Adobe Target Response token.

Apart from an activity name you can store and use different other things from Mbox and use it to create advanced activities to the target audience.
Also, you can store this in local storage or push it into the data layer.  You'll need to make changes in the following code accordingly.

To store Activity names firing on a page, you can try creating a rule in Adobe launch on library loaded (Page top) event and fire it on Activity URL where you want to run the test
Add the following custom code for a rule: invokes an event which will check the response token if it's empty it'll not return any value. Or if there is any response value it will store activity names in an array activityNames(as per following code).

document.addEventListener(, function(e) {
    var tokens = e.detail.responseTokens;

    if (isEmpty(tokens)) {

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

    uniqueTokens.forEach(function(token) {


  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]; })

  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]; });

This will store activity names in a cookie

No comments:

Post a Comment

Featured Post

[Solved] How to get current location of user using javascript?(Example code)

How to get the current location of a user using javascript? You might think to get a user's location is a difficult task, but it&...

Popular Posts