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