Is it possible to access mbox / user profile data through JavaScript? | Community
Skip to main content
amberb67455123
May 12, 2021
Solved

Is it possible to access mbox / user profile data through JavaScript?

  • May 12, 2021
  • 2 replies
  • 3372 views

I'm trying to work with user profile data (category affinity specifically) to implement a custom solution. I'm wondering if it's possible to read that data using JavaScript rather than using Target's built-in category affinity options. I can see this data in the mbox JSON file that's being loaded on our site if I enable the Target trace, but I haven't found a way to access that data programmatically.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ryanr7

Hi @amberb67455123,

Are you trying to get a visitor's category affinity value back to the page so you can run some client-side JS with it? If that is what you are trying to do you can create a custom modification offer in the VEC that writes a script back to the page and sets the category affinity value to some JS variable. To write Target profile values into experience content/offers see this help doc: https://experienceleague.adobe.com/docs/target/using/experiences/offers/passing-profile-attributes-to-the-html-offer.html?lang=en#implementation. I think the way to pass category affinity would be with: ${user.endpoint.categoryAffinity}. So you could create a custom modification like this:

 

<script>var catAff = "${user.endpoint.categoryAffinity}";</script>

 

And then your client-side JS could reference the catAff value as needed.

2 replies

ryanr7Adobe EmployeeAccepted solution
Adobe Employee
May 18, 2021

Hi @amberb67455123,

Are you trying to get a visitor's category affinity value back to the page so you can run some client-side JS with it? If that is what you are trying to do you can create a custom modification offer in the VEC that writes a script back to the page and sets the category affinity value to some JS variable. To write Target profile values into experience content/offers see this help doc: https://experienceleague.adobe.com/docs/target/using/experiences/offers/passing-profile-attributes-to-the-html-offer.html?lang=en#implementation. I think the way to pass category affinity would be with: ${user.endpoint.categoryAffinity}. So you could create a custom modification like this:

 

<script>var catAff = "${user.endpoint.categoryAffinity}";</script>

 

And then your client-side JS could reference the catAff value as needed.

amberb67455123
May 18, 2021
That's exactly what I'm trying to do, thanks! This all makes sense but when I try to implement it, the script shows up under "AT: Failed actions" in the console and does not run (so the variable is not available for client side code). I was able to see the category affinity when adding it in HTML (wrapped in <p>), but for some reason when trying to assign it to a variable in JavaScript it is failing. The code I used is exactly what you have above, and I added it as a custom code modification in an XT activity. If you have any ideas on how to get past this issue, that would be great! If not, thanks for pointing me in the right direction.