How to get user ip adress with wix velo?

I couldn’t find any working example to get users ip adress. I tried every example code and example wix websites to get ip adress but none of them worked on the client side. (They are working perfectly on backend but it always giving me wix servers ip adresss) What is the up-to-date method to get ip adress of the user and log it on console? Help would be appreciated.

Perhaps this can help…
https://russian-dima.wixsite.com/meinewebsite/ip-adress

Did you try the website ? Its not working, not showing the ip please try it.As I said I can’t find any working example

@makislaskos28968 Everything works just fine for me…

If you wish to use wix only, you can create a GET http-function that returns the request.ip
https://www.wix.com/velo/reference/wix-http-functions/wixhttpfunctionrequest-obj/ip

Good to know! Thanks for the tip.

I’d suggest to handle any potential CORS (Cross-Origin Resource Sharing) issues that may arise when making requests from the client side.

One workaround is to utilize a third-party service like ipify. org, which provides an API for fetching the user’s IP address. You can make an HTTP request to this service from your client-side code and log the returned IP address to the console using JavaScript.
Here’s a simple example to get you started:
fetch(‘api. ipify. org? format=json’)
.then(response => response.json())
.then(data => console.log(‘User IP Address:’, data.ip))
.catch(error => console.error(‘Error fetching IP address:’, error));
For more information on IP addresses and networking, you can check out this article about 1921681. I hope this helps someone.

One workaround is to utilize a third-party service like ipify.org, which provides an API for fetching the user’s IP address. You can make an HTTP request to this service from your client-side code and log the returned IP address to the console using JavaScript.

Since the last answer was posted a while ago, I’ve also found a way to get the user’s IP. You can test the solution directly on a page — it’s working fine on my end.

import { fetch } from 'wix-fetch';

$w.onReady(function () {
  // IP & location info using ipwho.is
  fetch('https://ipwho.is/')
    .then(res => res.json())
    .then(data => {
      if (data.success) {
        console.log("IP:", data.ip);
        console.log("Country:", data.country);
      } else {
        console.error("ipwho.is failed:", data.message);
      }
    })
    .catch(error => {
      console.error("Error fetching IP/location data:", error);
    });
});

Have a fabulous day!

1 Like

Hey @Andrian, it turns out that Google flags the website if we use this API. The infamous red screen with the message “Attackers might be trying to steal your information” appears and is a big trust-breaker. I had to comment out this API and submit the page for re-indexing for it to go away.

However Wix does seem to fetch all this info to show on the dashboard analytics, so it would be great if there was a Velo API itself to fetch all this data, instead of using a third party API, so that could prevent the website from being flagged unintentionally.

Interesting — it’s been working fine on my personal website for over a year without any issues. Since you brought it up, I just updated it to use a different API.

update: Some sources suggest that if an API temporarily uses HTTP instead of HTTPS, it could cause this issue.