I’ve seen a number of messages in this forum where somebody wants to find out information about the client such as country, currency, etc. The only solution I’ve seen so far is to GET the information from the API at extreme-ip-lookup.com which works great if you happen to be running on the client. For example,
fetch('https://extreme-ip-lookup.com/json', { method: 'get' })
.then( httpResponse => {
if (httpResponse.ok)
return httpResponse.json();
throw new Error("extreme-ip-lookup failed");
})
.then( json => {
const ipaddress = json.query;
const country = json.country;
...
If you are running code on the back end however, this solution will not work because the fetch() is coming from the Wix server. If you happen to be using a router, then I have a server-side solution using the API at ipgeolocation.io. You will need to set up an account for yourself but it’s free for low volumes. The request object passed to the router handler code has an attribute “ip” which is the IP address of the client. The router code looks like this:
fetch("https://api.ipgeolocation.io/ipgeo?apiKey=xxxxxxxxxxxxx&ip=" +
request.ip + "&fields=country_name,currency", { method: 'get' })
.then(results => {
if (results.ok)
return results.json();
throw new Error("ipgeolocation.io failed");
})
.then( results => {
const country = results.country_name;
...
The API is documented here: IP Geolocation API and IP Lookup Documentation
The response includes really useful info such as city, state/province, currency, time zone, etc.
Of course, maybe you’re not using a router but frankly it’s not much harder than using a regular Wix page and gives you a lot more control over the client interaction so I’d recommend you check it out. For example, I generally put my back-end and third party interactions in the server-side router code for the best and most reliable performance.
Thought I’d share