How to access all activities via Javascript

Avatar

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Jennifer_Huynh
Level 3

20-06-2019

Hi,

Is anyone know how to access all activities that are running on the same page via javascript on a  offer.

Replies

Avatar

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile
gaureshk3014423
Level 8

20-06-2019

Hi Jennifer Huynh​,

Can you clarify more about your question? What do you mean by "accessing all activities"?

Thanks,

Gauresh Kodag

Avatar

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Jennifer_Huynh
Level 3

20-06-2019

I have 3 activities running on home page.  In my activity #3 I want to be able to check if any activity running on the same page.  If there is, I would like to access the other activity name and store in a cookie

Avatar

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile
gaureshk3014423
Level 8

21-06-2019

I think we can get a list of all activities getting fired on a page in mbox response token and we can use them to create an audience (profile parameter) which you can use for your activity and store list of activities in a cookie with help of javascript custom code.

Okay, Jennifer Huynh​ let me check on this.

Thanks,

Gauresh Kodag

Avatar

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile
gaureshk3014423
Level 8

21-06-2019

Jennifer Huynh

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 (Activity 3)

Add the following custom code for a rule:

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

    });

    document.cookie="activityName="+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]; });

  }

This will store activity names in a cookie

Let me know if this helps

Thanks,

Gauresh Kodag.

Avatar

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Jennifer_Huynh
Level 3

24-06-2019

Can I still use this without Adobe Launch?

Avatar

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile
gaureshk3014423
Level 8

24-06-2019

You'll need to make changes in the code according to your need. Using it with Launch would be a more efficient way.

Thanks,

Gauresh Kodag.

Avatar

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Jennifer_Huynh
Level 3

25-06-2019

I am using inside my html offer via target global mbox.

document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e)

(e) always returns undefined.

Thanks

Avatar

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Jennifer_Huynh
Level 3

Likes

17 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Jennifer_Huynh
Level 3

25-06-2019

document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e) {
  console.log("Request succeeded", e.detail);
});

The addEventListener not firing.  I created an activity and put my codes inside an offer via target-global-mbox

Avatar

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile

Avatar
Springboard
Level 8
gaureshk3014423
Level 8

Likes

198 likes

Total Posts

168 posts

Correct reply

33 solutions
Top badges earned
Springboard
Validate 1
Contributor
Coach
Shape 10
View profile
gaureshk3014423
Level 8

25-06-2019

Hi Jennifer,

while adding custom code don't forget to put script inside <script></script> tag as follows.

<script>

document.addEventListener(adobe.target.event.REQUEST_SUCCEEDED, function(e) {

  console.log("Request succeeded", e.detail);

});

</script>

If you try to run and confirm the same code in the console it won't work. as adobe.target.event.REQUEST_SUCCEEDED is same as a load event. if you want to confirm in console, just change adobe.target.event.REQUEST_SUCCEEDED with 'click' as follows.

document.addEventListener('click', function(e) {

  console.log("Request succeeded", e.detail);

});

This will show you output in the messages tab in a console after you click anywhere in the body of page.

I tried in my dummy activity it works. You'll be able to see a message in the messages tab inside the console.

requestsucceed.PNG

Thanks,

Gauresh Kodag