Geolocation API for IP Address Lookup in Adobe Launch | BCS Geolocation API for IP Address Lookup in Adobe Launch | BCSBCS

Geolocation API for IP Address Lookup in Adobe Launch

Adobe Launch BCS 5 years ago (2019-12-05) 1576 Views 0 Comments

Update time: August 1, 2023

This article introduces how to obtain IP and geographic location through third-party API, In fact, geographic information in Adobe Analytics does the same.

The basic idea is: when the page is opened, first query the third-party API to obtain IP and geographic information, then write it into the cookie, and then execute other rules to send the cookie information to Adobe Analytics.

I use https://ipinfo.io/ here, you can open this URL, you can see the information you can get:

Geolocation API for IP Address Lookup in Adobe Launch

All fields are available.

Here I use the ip and city fields, the code is as follows:

<script type="application/javascript">
   $.get("https://ipinfo.io", function(response) {
             console.log("My public IP address is: ", response.ip);
          
     var cookieName= "Launch-ipnum";
     var cookieName2= "Launch-ipcity";
    var ipnumber  =response.ip;
     var ipcity  =response.city;
    var cookiePath  = "/";
 
    
    var expirationTime = 172800*15;                           
    expirationTime = expirationTime * 1000;
 
    var date = new Date();
    var dateTimeNow = date.getTime();
    date.setTime(dateTimeNow + expirationTime);
 
    var expirationTime = date.toUTCString();
 
    document.cookie = cookieName+"="+ipnumber+"; expires="+expirationTime+"; path="+cookiePath;
      document.cookie = cookieName2+"="+ipcity+"; expires="+expirationTime+"; path="+cookiePath;
        }, "json")
</script>

Geolocation API for IP Address Lookup in Adobe Launch

Note: Set the order to smaller data to ensure faster execution.

Then I published a test and saw that our ip and city were written into the cookie:

Geolocation API for IP Address Lookup in Adobe Launch

 

The next step is to read the cookie into the data element, and then send it to Adobe Analytics using eVars. Go and try it! !!


If you don't understand, You can leave a comment below.
Like (0)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website