How to get your visitor’s location from their IP address

Use JavaScript to detect the country and location of your website visitors from their IP address and offer different payment options or offer purchasing power parity.

The PayPal site mentions a list of 200 countries where the PayPal service is officially available. There are approximately 46 countries and regions remaining where buyers cannot transact with PayPal.

As shown in the Google map above, regions where PayPal is not available include Afghanistan, Bangladesh, Cuba, Ghana, Iraq, Iran, North Korea, Lebanon, Liberia , Libya, Pakistan, Palestine, Sudan, Syria, Turkey and Uzbekistan.

If you have a digital goods store that relies exclusively on the PayPal service for processing payments, you could lose customers because customers from countries like Bangladesh, Turkey, or Pakistan wouldn’t be able to make payments. .

As an alternative, you can sign up for a non-U.S. Payment processing service – Paddle and FastSpring are good alternatives – and offer them as payment options on the payment screen to customers accessing your website from countries where PayPal is not available.

Detect the country of your website visitors

I implemented a similar technique for my Google add-ons website and it seems to be working fine. The website uses PayPal and Stripe as their default payment handler, but if someone arrives from an unsupported country, the PayPal buttons are hidden and they are offered a payment option with Paddle.

To get the location of the website visitor, I use the service that quickly resolves the visitor’s IP address in their country. If you collect the service, it returns the ISO code of the country of the computer that made the HTTP request.

const getVisitorCountry = () => {
  return new Promise((resolve, reject) => {
      .then((response) => response.text())
      .then((data) => {
        const [status, country] = String(data).split(";");
        if (status !== "1") {
          throw new Error("Unable to fetch country");
      .catch(() => {

getVisitorCountry().then((country) => {
  if (["PK", "BD", "TR", "AF"].indexOf(country) !== -1) {
  } else {

Some online stores follow the “purchasing power parity” theory (learn more) where non-tangible goods such as video lessons and software licenses are dynamically priced based on the country of the customers. The above client-side approach to detecting the location of the visitor can also be useful in such scenarios.

Purchasing power parity

About Sharon Joseph

Check Also

PwC Report, Marketing and Advertising News, AND BrandEquity

TV advertising continued to grow in 2020, despite COVID, reaching Rs 35,015 crore. India’s entertainment …

Leave a Reply

Your email address will not be published. Required fields are marked *