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:
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>
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:
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! !!