Skip to main content
Level 2
Jan 25, 2024 8:31 AM UTC
Solved

Create Audience on the basis of cookie values

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
d_venkateshAccepted solution
Adobe Employee
Jan 30, 2024 8:34 AM UTC

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);
  }
})

 

 

6 replies

Gokul_Agiwal
Community Advisor
Community Advisor
Jan 25, 2024 9:47 AM UTC

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. 

Translate
Thanks, Gokul
varun790Author
Level 2
Jan 25, 2024 12:45 PM UTC

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"

Audience

 

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

 

 

 

Translate
Adobe Employee
Jan 25, 2024 11:53 AM UTC

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!

Translate
varun790Author
Level 2
Jan 29, 2024 11:37 AM UTC

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

Translate
d_venkateshAdobe EmployeeAccepted solution
Adobe Employee
Jan 30, 2024 8:34 AM UTC

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);
  }
})

 

 

Translate