Highlighted

Read cookie using target profile script

Avatar

Avatar

rajarajanr71853

Avatar

rajarajanr71853

rajarajanr71853

02-02-2016

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

Replies

Highlighted

Avatar

Avatar

RajneeshGautam-

Avatar

RajneeshGautam-

RajneeshGautam-

04-02-2016

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

Highlighted

Avatar

Avatar

rajarajanr71853

Avatar

rajarajanr71853

rajarajanr71853

04-02-2016

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

Highlighted

Avatar

Avatar

ruchaj45469490

Avatar

ruchaj45469490

ruchaj45469490

10-03-2016

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

Highlighted

Avatar

Avatar

bhawkins

Avatar

bhawkins

bhawkins

10-03-2016

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

Avatar

rajarajanr71853

Avatar

rajarajanr71853

rajarajanr71853

10-03-2016

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

Highlighted

Avatar

Avatar

eric9876588

Avatar

eric9876588

eric9876588

31-07-2018

The link doesn't seem to work