Expand my Community achievements bar.

Profile Script to create user Attributes not working?

Avatar

Level 1

Hi all,

we want to use Adobe Target to personalize a Banner on our Website. Our Website is set up in 25 languages.

We already implemented Adobe Target and can personalize our Banner using Audiences and a JSON-Offer. This works fine. So e.g. i choose the audience "de" for Germany and the customer_segment "xs", i create the JSON-Offer for this Audience and everything works fine.

 

The problem is that i need to create for each language and customer_segment combination a new experience. If i have 4 customer segments -> then i have to create 4 x 25 (languages) = 100 Experiences.

I think it would be better to have only 4 Experiences (the 4 customer segment audiences) and the experience/ JSON-Offer uses dynamic values for the correct translation of each element.

Our implemented mbox is sending the "userLanguage" with the value of e.g. "de".

The idea is that we use "Profile Scripts" to create the translation dependent on the "userLanguage"

 

So the final offer JSON offer contains placeholders:

{
  "imageUrl": "${user.imageUrl}",
  "headline": "${user.headline}",
  "subHeadline": "${user.subHeadline}",
  "buttonText": "${user.buttonText}",
  "buttonUrl": "${user.buttonUrl}"
}

 

The current problem. The placeholders are empty. Which means i don´t have the profile attributes...

So the problem probably sits in this profile script i use to accomplish this...

if (mbox.name == 'cockpit_banner') {
    var lang = mbox.param('userLanguage');

    if (lang == 'de') {
        user.set('imageUrl', 'xxx.jpg');
        user.set('headline', 'DE Headline');
        user.set('subHeadline', 'DE Subheadline');
        user.set('buttonText', 'DE Button Text');
        user.set('buttonUrl', 'https://www.123.de');
    } else {
        user.set('imageUrl', 'xxx.jpg');
        user.set('headline', 'Default Headline');
        user.set('subHeadline', 'Default Subheadline');
        user.set('buttonText', 'Default buttonText');
        user.set('buttonUrl', 'https://www.123.com');
    }
}

I already double and triple checked that userLanguage is transferred and also checked that the mbox name is cockpit_banner.
The script isn´t showing any errors.

I checked the implementation multiple times, as mentioned when using the placeholders the values are empty (so the banner is not shown), but technically the rest is working..., so the problem is that the profile script is not setting the user attributes.. but why?

In general, is this the right approach?
Is this logic in general possible, or do i have misunderstood some adobe documentation?

Best Regards and thank you for looking into this,
René

3 Replies

Avatar

Community Advisor

Hi @Reneva2 ,

 

If your profile script in Adobe Target isn't creating user attributes correctly, it's likely because you're trying to access data directly from the page using JavaScript functions that aren't available server-side within the profile script; make sure to pass the necessary data into Target through an mbox request first, then access it us.

 

Key points to remember:
  • Data needs to be passed in:
    Profile scripts run server-side, so they can't directly read data from the webpage. You need to pass the relevant user data into Target through an mbox request or other methods before using it in your script. 
     
  • Accessing data in the script:
    Use the crs.get() function to access passed data within your profile script, specifying the data source and attribute name correctly. 
     
    Example:
    // Assuming you have a "user_tier" parameter passed in the mbox request if (crs.get('mbox.user_tier') === 'premium') { crs.set('user.vipStatus', 'true'); // Sets the "vipStatus" attribute to "true" for premium users } else { crs.set('user.vipStatus', 'false'); }
     
    Troubleshooting steps:
    • Check data passing:
      Verify that the necessary data is being correctly passed into Target through the mbox request using parameters. 
       
    • Syntax review:
      Double-check your profile script syntax, ensuring you're using the correct crs.get() and crs.set() functions with the correct data source and attribute names. 
       
    • Debug using Target debugger:
      Use the Adobe Target debugger to inspect the incoming data and see how your profile script is executing. 
       
    • Check for invalid Javascript:
      Profile scripts only support a subset of JavaScript functions, so avoid using any functions that are not allowed in this environment. 

Avatar

Level 9

Hi @Reneva2 , 

 

Instead of using :

user.set('imageUrl', 'xxx.jpg');

Can you try using :

user.setLocal('imageUrl', 'xxx.jpg');

 

Let me know if it helps. 

 

Best regards, 

Vaibhav Mathur

Avatar

Level 9

@Reneva2  suggest to use below 

using java Script on your page

- Window onload event get language type from window.navigator 

- then pass language value to target via target param 

- read passed language param value at server side