Expand my Community achievements bar.

SOLVED

Create Audience on the basis of cookie values

Avatar

Level 3

I have a requirement where user setting Country code in cookie or local storage.

Then on page load we should get this value and check country code and make condition on basis of that in audience.

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi @varun790,

 

I meant by adding the mbox parameter using either the launch or target getoffer method. 

 

adobe.target.getOffer({
  "mbox": "target-global-mbox",
  "params": {
     "a": 1,
     "b": 2
  },
  "success": function(offer) {
        adobe.target.applyOffer( {
           "mbox": "target-global-mbox",
           "offer": offer
        } );
  },
  "error": function(status, error) {
      console.log('Error', status, error);
  }
})

 

 

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @varun790 

Yes, you can able to achieve using Profile Script and that way you can read the cookie and fetch the countryCode value and later used for your defining audience through Visitor Profile section. 

 

Here is the small snippet for read a cookie using Profile script. 

// Read a Cookie
var cookies = user.header('cookie');
if (cookies.indexOf('YOUR_COOKIE_VAL') >= 0) {return "true";}
else {return "false";} }

Hope this helps. 

Avatar

Level 3

Hi Gokul, Thanks for the reply. I tried the same but it it did not worked.

 

profile script(get_country_code):-  I am saving the cookie in browser as "countryCode=US"

varun790_0-1706186580596.png

Audience

varun790_1-1706186641244.png

 

And then I used this audience on the page, but it did not worked.

 

 

 

Avatar

Level 3

Hi Gokul can you help me getting the cookie values as well here

Avatar

Employee

Hi @varun790 

 

Since profile scripts run on the server side, direct access to cookie values is not possible. To utilize cookie information at the audience level, first read the cookie value and then pass it as a standard mbox parameter.

 

Hope this helps!

Avatar

Level 3

I am not using mbox since we have upgraded to Adobe target version V2

Avatar

Correct answer by
Employee

Hi @varun790,

 

I meant by adding the mbox parameter using either the launch or target getoffer method. 

 

adobe.target.getOffer({
  "mbox": "target-global-mbox",
  "params": {
     "a": 1,
     "b": 2
  },
  "success": function(offer) {
        adobe.target.applyOffer( {
           "mbox": "target-global-mbox",
           "offer": offer
        } );
  },
  "error": function(status, error) {
      console.log('Error', status, error);
  }
})