Use ipdata’s Geolocation Data to Protect & Customize Your Site

3D ad banner ad revenue ad revenues adobe XD Advanced advanced-css-tools advanced-css-tutorials AdvancedCSS AdvancedCSS-hub agency Agile Agile Development ai Ajax Alex Skill Kit Alexa Alexa skill AlexW Amazon Alexa amazon developer analytics Angelap angular AngularJS Animation anime.js ANN api apollo Appsflyer array methods artificial neural network Async async components AurelioD automation Avocode AWS AWS Lambda axios b2b b2c baas background background eraser tool Banner banner ad Bannersnack bawmedia bem bitcoin black friday Blogs bootstrap bot browser testing Browsers build process bundler Business business success C Canvas & SVG career Career Advancement CDN Chakra UI charting chat app chatbots ChatKit chrome chrome developer tools chrome extension chrome extensions chromium ciphering cli cli tools climate climate action clojure Cloud cloud hosting CloudFlare Cloudways cms CNN code challenge ColinI collaboration collaboration tools committing changes compiler components const assertions constructs content content delivery network context api convoluted neural network create react app cron job cross browser testing cross platform development cross-browser cryptocurrencies cryptocurrency CSS CSS Animations CSS Architecture css blur css challenge css framework css frameworks css grid css modules CSS print css rem css typography CSS-in-JS CSS3 css3 transforms D3.js data science data visualization database databases debugging decoupled cms deep linking delay Design Design & UX design career design handoff Detox dev environment developer tools DevOps devtools diagnostic analytics digit recognition digital agency digitalocean Discord discounts django Docker Docker Containers E-commerce ECMAScript edge computing editor elastic em units employment encryption end-to-end testing energy energy usage Entrepreneur Entrepreneurship environment erasing backgrounds es6 ES6 classes eslint Expo Express FaaS face detection face recognition fast wordpress themes Feathers Feathers.js figma flask flatfile flexible wordpress theme framework Frameworks freelancing functional programming functions gatsby generators geolocation getting a job gitCS github github API Google Photos GraphCMS graphing graphql Growth Grunt grunt-watch Gulp haskell headless CMS hooks hosting HTML HTML & CSS html preprocessor HTML5 HTML5 Dev Center IAAS IDE Illustration image optimization immutability Interview ionic IP2Location ipdata jade jamesh JavaScript javascript framework javascript frameworks javascript tooling Jest job job interview joelf jQuery jQuery functions jquery get url params jquery string functions jQuery.each() jQuery.each() Array Example jquery4u js js framework JS tooling Keras keycdn kubernetes lambdatest launch checklist Layout learn javascript learn typescript learn-advanced-css learn-modernjs Learn-Node-JS learn-vue Let's Encrypt Lift linux linux containers location tracking LouisL machine learning Managed managed hosting mariap marvel MATLAB MBaaS mekanism mind map mind mapping mindmapping Mobile mobile attribution Mobile Design modernjs modernjs-hub modernjs-tools modernjs-tutorials modules monday mongodb MTCNN multi-threading mysql MySQL install natural language processing Navigation navigation library nest Next.js nilsonj node node version manager node-hub Node-JS-Tools Node-JS-Tutorials node-mysql module Node.js nodejs noops npm nvm objects octobercms Offers on-premise online publishing PaaS Package Management package manager pair programming pairing pause Percy Performance Photography & Imagery Photoshop Photoshop Tutorials & Articles pip pipeline portfolio portfolio builders preprocessors prettier print styles Prisma Private Class Fields product design Profitability Programming programming job PubNub Pug Puppeteer Pusher python python framework python interview python job Quasar query strings quick-tip quiz quote builders r Raw JavaScript React react components React Hooks React Hooks Form React native reactive Reactive Programming reactive web apps read offline Reat native elements Recurring Payments recursive types RedBox redux rem units remote work remote work tips removing backgrounds resilient Resources responsive REST restful api Review SaaS sampling sass Scss self sencha server-side serverless serverless computing shared hosting sharing state sharpen side project siteground sketch slashdata sleep Software software commits sorting specifications speech recognition speech recognition api sponsored ssl Stack Overflow state state management static module bundler StudioWorks Styled Components styling React components survey sustainability svelte sympli Tailwind task runner telegram bots Template engine Testing text to speech Themes Tic Tac Toe Tinder toggle Tolerance tooling tooling anxiety tools Tools & Libraries transformations TypeScript typescript skills Ubuntu UI UI Design Usability user experience user research UX ux issues vanilla javascript VGGFace2 virtual machine visual testing voice recognition vps vue Vue CLI vue dev environment vue-hub vue-tutorials vue.js vuetify vuex wait WatermelonDB Web Web Design web hosting Web Hosting & Domains Web standards web workers webpack website builders website performance WebSockets windows windows 10 home Windows Subsystem for Linux Windows Terminal wix women women in tech WordPress wordpress plugin wordpress themes WordPress theming work workers workflow working remotely workplaces WPEngine WSL WSL2 YellowBox Zeplin

This article was created in partnership with GoGetSSL. Thank you for supporting the partners who make SitePoint possible.

Modern websites are becoming more and more effective at customizing content based on their visitors’ location. They can redirect users to a page in their own language, display prices in the local currency, pre-fill webforms with location information, and show the current time and date for the correct timezone.

ipdata is a low-latency API that provides website owners with a wide variety of information about their visitors based on IP address (IPv4 and IPv6). Think of it as an IP geolocation and threat intelligence API.

By using a visitor’s IP address you can learn their continent, country, region, city, latitude and longitude, organization or ISP, and timezone. The API also detects Proxy and Tor users, as well as known spammers and bad bots. Blocking these risks will protect your website, and reduce the need for security strategies like CAPTCHA.

Let’s look specifically at some ways ipdata can help, and how to implement them on your own website.

Redirect Visitors and Localize Content

When you visit the ipdata website you’ll immediately see what the service is capable of. Everything that can be learned from your own IP address is displayed.

ipdata data return example

That data includes:

  • Whether you’re in the EU,
  • Your city,
  • State or region (and region code),
  • Country (and country code),
  • Continent (and continent code),
  • Latitude and longitude,
  • Postal or zip code,
  • Country calling code,
  • Your country’s flag emoji,
  • Your service provider’s ASN and carrier information,
  • Languages,
  • Currency (name, code, symbol, plural),
  • Time zone (name and abbreviation, offset, daylight savings time, current time),
  • Threat information (Tor, Proxy, anonymous, known attacker, known abuser, threat, bogon).

You can call ipdata's API on each page request to geolocate your visitors and localize their content. Here’s a handful of ideas of what you can achieve:

  • Restrict or block access to your content to specific countries or continents,
  • Redirect users to country-specific (or language-specific) sites or pages,
  • Pre-fill your webforms with their location data,
  • Show your visitors their local time and weather,
  • Display events that are near your visitors, or available flights in their area,
  • Serve targeted ads based on location,
  • Enforce GDPR compliance,
  • Automatically convert prices on your e-commerce store to their local currency, using the correct currency symbol,
  • More accurately analyze where your traffic is coming from.

You can get a client’s IP address using JavaScript, but it’s a bit of work. Instead, use ipdata’s API. It’s super-fast and reliable across all browsers. Here’s the code:

    $.get("", function(response) {
    }, "jsonp");

Once you have a visitor’s API address, ipdata’s documentation shows you how to get their location in 26 different languages. You’ll also find detailed tutorials on how to code for a variety of use cases. Here are a few examples.

To block (or allow) users by country, look up the ISO 3166 ALPHA-2 Country Codes for the ones you want to blacklist or whitelist. Then follow this sample code to learn how to blacklist or whitelist them.

    // List of countries we want to block
    // To see this in action add your country code to the array
    var blacklist = ['US', 'CA', 'UK', 'IN']

    // Getting the country code from the user's IP
    $.get("", function (response) {

      // Checking if the user's country code is in the blacklist
      // You could inverse the logic here to use a whitelist instead
      if (blacklist.includes(response.country_code)) {
        alert('This content is not available at your location.');
      } else {
        alert("You're allowed to see this!")
    }, "jsonp");

Redirecting users by country is useful if you have country-specific online stores, or if you have a separate page with content in their language or with country-specific contact details.

Here’s an example of how to redirect your visitors located in Germany and Australia. They will be redirected from to and

    // Getting the country code from the user's IP
    $.get("", function (response) {
      if (response.country_code == 'UK') {
        window.location.href = "";
        } else if (response.country_code == 'DE') {
        window.location.href = "";
        } else if (response.country_code == 'AU') {
        window.location.href = "";
    }, "jsonp");

You can also personalize the content of your site depending on the user’s location. Here’s an example that displays a special offer to UK visitors only:

    // Getting the country name from the user's IP
    $.get("", function (response) {
      if (response.country_code == 'UK') {
        alert("Special offer for all our users from " +response.country_name+ "!");
    }, "jsonp");

Instead of targeting a whole country, you can drill down to region, city or postal code (zip code). Alternatively, you could target a time zone or specific currency.

You can further personalize your content by displaying the user’s local time (adjusted for DST) and local currency symbol. To request time zone data for IP address “”:

    $ curl

You’ll receive this response, which includes the name and abbreviation of the time zone, its UTC offset, whether it is currently DST, and the local time:

        "name": "America/Los_Angeles",
        "abbr": "PDT",
        "offset": "-0700",
        "is_dst": true,
        "current_time": "2019-03-27T01:13:48.930025-07:00"

Currency detection is similar. Here’s an example for the IP address “”:


And the response:

        "name": "Australian Dollar",
        "code": "AUD",
        "symbol": "AU$",
        "native": "$",
        "plural": "Australian dollars"

Protect Your Website from Threats

You can also use ipdata to identify potential threats against your website. They maintain a database of over 600 million malicious IP addresses, open proxies, Tor nodes, spammers, botnets, and attackers. These are aggregated only from high-quality, authoritative sources. You can use this information in a variety of ways:

  • Protect your comments by blocking known spammers and bad bots, alleviating the need for CAPTCHA,
  • Detect frauds by determining if their credit card is from a country different to where they are located,
  • Block anonymous traffic to eliminate the risks that come from such networks,
  • Block high-risk countries, such as the countries where most of your malware and attacks originate,
  • Prevent “free trial abuse” by detecting Proxy and Tor users.

Here’s how to access the threat data for the IP address “”:


The request generates the following response:

        "is_tor": true,
        "is_proxy": false,
        "is_anonymous": true,
        "is_known_attacker": false,
        "is_known_abuser": false,
        "is_threat": false,
        "is_bogon": false

The visitor is using a Tor network. is_anonymous is true if the visitor is either a Tor or Proxy user. You can use ipdata to stop anonymous users creating an account. Here’s some sample code from the official documentation:

    // Getting the anonymity status from the user's IP
    $.get("", function (response) {
      if (response.threat.is_anonymous) {
        alert("You are not allowed to create an account.");
    }, "jsonp");

You can get more specific, for example, by blocking Proxy users but letting Tor users through:

    // Getting the anonymity status from the user's IP
    $.get("", function (response) {
      if (response.threat.is_proxy) {
        alert("You are not allowed to create an account.");
    }, "jsonp");

Some users are repeat offenders, having been repeatedly reported by admins of other websites for spam or malicious activity. You can stop them from creating an account by blocking them if one of these fields are true:

  • is_known_abuser: IP addresses that have been reported to be sources of spam,
  • is_known_attacker: IPs that have been reported to be the source of malicious activity.

Why Choose ipdata?

ipdata compares very favorably with other IP Geolocation APIs. It is written in Python 3 with an average execution time of 2.9 ms. It’s fast and reliable enough to keep a long list of clients happy, including Comcast, Redhat, Cooperpress, Sphero, AMD, and NASA.

ipdata is highly scalable, with low latency globally. The API serves millions of requests every day at an average speed of just ~65ms, and runs in eleven data centers around the world:

  • 4 in the US,
  • 1 in Canada,
  • 2 in Europe (London and Frankfurt),
  • 1 in India (Mumbai),
  • 1 in South America (Sao Paulo),
  • 1 in Europe (Seol), and
  • 1 in Australia (Sydney).

According to Jonathan Kosgei, the Founder of ipdata, execution time is kept low by not doing any database reads or writes in the application code. “A separate authorizer function handles getting usage data from DynamoDB and authorizing users based on whether they’re within their quota or not. And its results are cached.”

Start Geolocating Your Visitors with ipdata

By now I’m sure you’ve thought of a dozen ways you can use ipdata to enhance and protect your website, or those of your clients. Sign up for free and start testing it!

The service is Jonathan Kosgei’s first SaaS, and he’s quite transparent about the smart way he set it up and the lessons he learned along the way. Learn from his experiences in his guest posts:

The post Use ipdata’s Geolocation Data to Protect & Customize Your Site appeared first on SitePoint.

Original Article

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.