Expand my Community achievements bar.

SOLVED

Using Profile Script token values in Activities A/B test custom code

Avatar

Level 2

Hi, for Profile Scripts you can use JavaScript arrays and objects as the values and it works fine within the Profile Script. However accessing the value in an Activity A/B test via Custom Code Modifications the values aren't deserialized the same.

Profile Script (user.testValue)

return ['test', 'blue'];

or

return {key1: 1, key2: 2};

Within an Activity A/B test modification custom code

var profileValue = "${user.testValue}";

console.log(profileValue);

The console output will be

and

Basically for string arrays, the quotes are removed when accessing the value within an Activity and the JS object is returned in a different format. Is there a method of accessing the token values other than ${user.token} that would retrieve the value correctly?

I only found this storing an array of strings in a profile attribute  thread with the same issue, but the answer didn't actually address the question.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Just out of curiosity, why do you need the quotes?

Have you considered setting the values as ["'test'", "'blue'"]

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Just out of curiosity, why do you need the quotes?

Have you considered setting the values as ["'test'", "'blue'"]

Avatar

Level 2

I need the quotes so I can just use the value as a string array like below.

var profileValue = ${user.testValue}; 

console.log(profileValue[0]); 

to get

I could set the value as ["'test'", "'blue'"] but then I would have to manage the extra quotes within the Profile Script. Also, that doesn't work.

Avatar

Level 10

Could you explain the full scenario so that it will be clear why you are looking exactly for "string array'?

Avatar

Level 2

An example use case would be storing the last view pages. In the Profile Script, I can just add page.path into an array and then use that array in the Activity.

Profile Script (user.testValue)

var testValue = user.get('testValue') ||[];

testValue.push(page.path);

return testValue.slice(0, 10);

in Activity custom code

var lastPageViews = ${user.testValue}; 

console.log(lastPageViews[0]); 

In this example I can easy store the last 10 pages the user viewed and get access to it in an A/B test. This is just an example and I know I can achieve it in other ways, but having the ability to easily store data as a string array or as a JavaScript object greatly simplifies things.

Is this a bug or a limitation in Target?

Thanks.

Avatar

Level 2

I am having this very same issues here as well. Is there any official response to this? Looks like storing data through profile scripts and retrieving it from the offers are focused on just chains of alpha-numerical characters.

How we are supposed to build a rich profile across multiple websites with just this option? The only array that seems to exist in here is the Category Affinities which btw, as far as I know, there can just exist one instance per profile.