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