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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Read cookie using target profile script

Avatar

Level 2

Hi All,

How can i read cookie value in target profile script?

I tried to use this script "user.header('cookie')". But i don't know how to get specific cookie value.

Kindly help me.

Thank you,

Rajarajan R

1 Reply

Avatar

Level 2

Hi Raja,

 

You can use following code to read specific cookie:

var cookieName = 'aam_tnt';

var headerCookie = "; " + document.cookie;

var parts = headerCookie.split("; " + cookieName + "=");

  if (parts.length == 2) return parts.pop().split(";").shift(); 

 

Hope this helps

 

Rajneesh

Avatar

Level 2

Hi Rajneesh,

We can't use plan JS inside Profile Script. Its throwing error if i use it. We can only use the mbox API.

I tried using user.header('cookie'),but i don't know how to get exact value of a cookie.

And i even tried with mboxFactoryDefault.getCookieManager()​.getCookie(name), its not working .

Regards,

Rajarajan R

Avatar

Level 1

Hi Raja,

I have also encountered a similar issue with reading cookie's in a profile script.

Were you able to find a solution?

Regards,

Rucha

Avatar

Level 2

The user. scripts are server side and cookies are client side.  Here is an easy example to do this:

 

http://www.testandtargeting.com/demo/cookie/

There is a function that is added to the mbox.js at the bottom and take a look what is added to the mboxCreate.  

Avatar

Level 2

Hi Rucha,

You can pass the cookie value using Page Parameter or mBox Parameter. And you can find the name"offercode" in Target audiences under visitor profile.

By Page Parameter : (Page level Code)

targetPageParams = function() { return { "offercode": getCookie("name"); }; };

Check this https://marketing.adobe.com/resources/help/en_US/target/ov/c_pass_parameters_to_global_mbox.html

By mBox Parameter (Page level Code)

mboxCreate('mboxname','offercode='+getCookie("name"));

Check this https://marketing.adobe.com/resources/help/en_US/target/ov/t_orderconfirm_create.html 

You can find the offercode parameter under audience -> visitor profile

 

Rajarajan R