Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Profile Attribute - read cookie - write profile attribute value

moritzk15702306
Level 2
Level 2

Hi,

i try to use a "profile attribute - type: script attribute" to recognize if the user has a cookie "last-login" and write the information to the user profile, so we can target the campagn. The campagn is a redirect offer and the correct displaymbox is chosen.

I can see that the script WILL work because i can write custom values to the "user.cookieReturning", but if i try to access the cookie with document.cookie the wysiwyg editor throws an error "document is undefined". I saw some examples in the documentation where input fields a read and values written to profiles, so i assume it can work. The other solution would be to write a parameter to the mboxCreate, but we would like to solve it by target itselfs.

Questions:

1.) Is it possible to read "document-based" cookies before target decides what to to? (redirect or html offer)

2.) In which scope does the attribute scripts run? Document, window are all undefined.

3.) Another try with a Plugin for all pages did work, but i couldnt acces the profile/user variables, is this possible?

Some code:

Read cookie and save/return the result

var state = false try{ function readCookie(n){n+='=';for(var a=document.cookie.split(/;\s*/),i=a.length-1;i>=0;i--)if(!a[i].indexOf(n))return a[i].replace(n,'');} state = (typeof(readCookie('last-login'))!=="undefined"); profile.setLocal("cookieReturning", state); } catch (e) {     state = ""+e; } return state;

 

Debugged with mboxTrace

...

"profile": { "client": "<customer>", "visitorId": { "tntId": "1436519868442-317739", "profileLocation": "26_16", "new": false }, "beforeExecutionProfileSnapshot": { "modifiedAt": "2015-07-10T05:43:03.313-04:00", "profileAttributes": { "user.cookieReturning": { "value": false, "modifiedAt": "2015-07-10T05:43:03.312-04:00" }, "previousSessionStart": { "value": 1436519868792, "modifiedAt": "2015-07-10T05:17:48.792-04:00" }, "sessionCount": { "value": 1, "modifiedAt": "2015-07-10T05:17:48.792-04:00" } } }, "afterExecutionProfileSnapshot": { "modifiedAt": "2015-07-10T06:07:46.899-04:00", "profileAttributes": { "user.cookieReturning": { "value": "ReferenceError: \"document\" is not defined.", "modifiedAt": "2015-07-10T06:07:46.898-04:00" }, "previousSessionStart": { "value": 1436519868792, "modifiedAt": "2015-07-10T05:17:48.792-04:00" }, "sessionCount": { "value": 1, "modifiedAt": "2015-07-10T05:17:48.792-04:00" } } } },

...

 

Best regards

Moritz

1 Accepted Solution
shekhardhiman
Correct answer by
Employee
Employee

Hi Moritz,

Thanks for reaching out to Adobe Community.

We can’t read the document from script profiles as they resolve on the Target server (against each mbox request that is sent in).

Script profiles will not recognise the document object.

You’d have to place this functionality in the mbox.js file or in an mbox response (possibly a plug-in) which has access to the document object.

I’d suggest sending parameters back based on cookie values. Tag management can help greatly with this!

Hope this helps!

Thanks!

View solution in original post

3 Replies
shekhardhiman
Correct answer by
Employee
Employee

Hi Moritz,

Thanks for reaching out to Adobe Community.

We can’t read the document from script profiles as they resolve on the Target server (against each mbox request that is sent in).

Script profiles will not recognise the document object.

You’d have to place this functionality in the mbox.js file or in an mbox response (possibly a plug-in) which has access to the document object.

I’d suggest sending parameters back based on cookie values. Tag management can help greatly with this!

Hope this helps!

Thanks!

View solution in original post

moritzk15702306
Level 2
Level 2

Thank you for the anwser. Thats everything i need to know.

I've got another question about the 'user.categoryAffinity'. I want to read the all the content of the array/object to see the score of each entry. Is that possible in a html-offer?

I know that i can read first affinity, but the affinities are empty? Is there a workaround like save them to another profile key?

<script> console.log("user.categoryAffinity", "${user.categoryAffinity}"); //e.g. ... "car" console.log("user.categoryAffinities", "${user.categoryAffinities}"); // "" </script>
moritzk15702306
Level 2
Level 2

I found the solution to write them into the profile and access them in a offer. Becareful with the naming something like "user.user-categoryAffinities-CONTENT" is not readable

 

"user.categoryAffinitiesContent": { "value": "car, flowers,", "modifiedAt": "2015-07-24T11:34:22.271-04:00" },