30 Geolocation API for IP Address Lookup | BCS

30 Geolocation API for IP Address Lookup

Adobe Launch BCS 8 months ago (12-05) 178 Views 0 Comments

This principle is relatively simple, similar to the second method of writing data into a cookie. The action is to call the third party API to use IP to query the geographic location and other information. Then the API will return the data,There are multiple ways to pass data to Adobe Launch. You can go to the data layer, it can be a custom event in Rule, you can also write it to cookies, js variables, etc.

I don’t recommend using custom events, this will  increase the usage of Call.

The function of this code is to get geographic information through API query, and then write the IP and geographic location into the cookie:

<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
	var cookieName= "Launch-ipnum";
	var cookieName2= "Launch-ipci";
    var ipnumber  =returnCitySN.cip;
    var ipcity  = returnCitySN.cname;
    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; 
</script>

30 Geolocation API for IP Address Lookup

 

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

 

30 Geolocation API for IP Address Lookup

 

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 or email me (haran.huang@ichdata.com).
Like (0)
Post my comment
Cancel comment
Expression Texture Bold Strikethrough Center Italic Sign in

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

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