Get the user country name in cookie through Adobe Target | Community
Skip to main content
Level 2
February 6, 2024
Solved

Get the user country name in cookie through Adobe Target

  • February 6, 2024
  • 1 reply
  • 762 views

I want to get the country of user through Adobe target in cookie value.

 

I do get geo.country in "delivery" call in Adobe target.

 

Any other way to achieve this.

@d_venkatesh @gokul_agiwal 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Rajneesh_Gautam_

hi @varun790  - there are 2 ways to achieve this:

1. Response tokens:

A. Enable the geo.country response-token

B. Use your applications's code to read it using Custom events (https://experienceleague.adobe.com/docs/target/using/administer/response-tokens.html?lang=en )

C. Update the cookie with the retrieved value

 

2. Adobe Target activity:

A. Setup an XT activity which runs on all pages (or on specific pages where you want to read country value)

B. In the experience-code, use dynamic parameter to retrieve the value of country. 

C. In the same experience-code, add logic to save the country-value in a cookie. Here's sample code:

function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } // Get the Geo-country from Adobe Target var country = "${profile.geolocation.country}"; // Set the cookie value with the country setCookie("user_country", country, 90);

1 reply

Rajneesh_Gautam_
Community Advisor
Rajneesh_Gautam_Community AdvisorAccepted solution
Community Advisor
February 6, 2024

hi @varun790  - there are 2 ways to achieve this:

1. Response tokens:

A. Enable the geo.country response-token

B. Use your applications's code to read it using Custom events (https://experienceleague.adobe.com/docs/target/using/administer/response-tokens.html?lang=en )

C. Update the cookie with the retrieved value

 

2. Adobe Target activity:

A. Setup an XT activity which runs on all pages (or on specific pages where you want to read country value)

B. In the experience-code, use dynamic parameter to retrieve the value of country. 

C. In the same experience-code, add logic to save the country-value in a cookie. Here's sample code:

function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } // Get the Geo-country from Adobe Target var country = "${profile.geolocation.country}"; // Set the cookie value with the country setCookie("user_country", country, 90);