Getting Started
To use ipstack, the first thing you’re going to want to do is register your details for a free API key (no credit card is required). The API key is a long string of numbers and letters that stops anyone else from accessing data with your account and using up your quota. ipstack’s basic lookup function is really simple: We just access the API, append the IP address we want to look up, and finally add a query string with the value pair “access_key” and your own API key, like this:http://api.ipstack.com/111.222.333.444?access_key=0a9b8c7d6e5f4g3h2i1jipstack then returns a whole host of data for you to use, ranging from the user’s country, city, and even a handy link to an SVG file of the user’s national flag.
Enhancing UX with Geolocation
Let’s say you’re selling online, and you want to offer different shipping rates. Most importantly you want to offer US-based customers free domestic shipping, and international customers cheap worldwide shipping. With ipstack it’s simple to detect which offer to show your users. We’re going to set up a really quick PHP query, to detect which message we should show the current user. First, we open the PHP file and build the query:<?php // Record my API key, and the URL to send the query to $API_KEY = "0a9b8c7d6e5f4g3h2i1j"; // <— CHANGE THIS TO YOUR API KEY $API_URL = "https://api.ipstack.com/"; // Detect the user’s IP address $USER_IP = $_SERVER["REMOTE_ADDR"]; // Build the API URL (url + ip address + api key) $IPSTACK_QUERY = $API_URL . $USER_IP . "?access_key=" . $API_KEY;Next we run the query and save the result:
// Init CURL $ch = curl_init($IPSTACK_QUERY); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Grab the data that’s returned $jd = curl_exec($ch); // Clean Up curl_close($ch); // Decode the data ipstack returned $result = json_decode($jd, true);Finally we pull the country code out of the query, compare it to the country code for the US (which is, unsurprisingly ‘us’), then output a different message depending on the result:
// Find the user’s country $user_country = $result["country_code"]; // Check if the user’s country is the United States $isUS = strtolower($result["country_code"]) === "us"; // Output the result if($isUS) { // Offer free shipping echo "Shipping is FREE within the USA!"; } else { // Offer international shipping echo "We ship worldwide for just $25!"; } ?>It really is that simple.
How ipstack Stacks Up
ipstack is one of the simplest geolocation services we’ve used. It offers an incredibly fast way to get started detecting where your users are. We would like to see a little more security; many geolocation services require you to register your domain and block other sites, which means that it’s safe to expose your API key—as it stands, you can’t use ipstack in JavaScript without risking exposing your API key. However, if you’re working in server-side code (as above) then ipstack is as secure as any other provider, and far quicker than most to implement. [pullquote]ipstack is one of the best geolocation services currently available[/pullquote] Based on our testing, ipstack is one of the fastest providers out there. Results were returned in milliseconds, and from a human perspective queries appeared to be returned instantaneously. Perhaps our favorite feature of ipstack is how much data it returns. Some services offer a country code lookup, then charge extra for region, or city lookups. ipstack’s policy is to deliver all of the information you could ever need, so you can work with data however it benefits your users.Conclusion
For simplicity, speed, scalability, and depth of information, we think ipstack is one of the best geolocation services currently available. Our testing was very limited, and we didn’t run any large-scale, intensive applications; however, the companies that do choose ipstack—notably, Microsoft, Samsung, and Airbnb—are handling huge volumes of users with no apparent issues. The potential enhancements to UX that knowing your user’s location allows, opens the door to much greater customer engagement. When you can have all of this for free, it seems crazy not to take advantage of it.WDD Staff
WDD staff are proud to be able to bring you this daily blog about web design and development. If there's something you think we should be talking about let us know @DesignerDepot.
Read Next
3 Essential Design Trends, May 2024
Integrated navigation elements, interactive typography, and digital overprints are three website design trends making…
How to Write World-Beating Web Content
Writing for the web is different from all other formats. We typically do not read to any real depth on the web; we…
By Louise North
20 Best New Websites, April 2024
Welcome to our sites of the month for April. With some websites, the details make all the difference, while in others,…
Exciting New Tools for Designers, April 2024
Welcome to our April tools collection. There are no practical jokes here, just practical gadgets, services, and apps to…
How Web Designers Can Stay Relevant in the Age of AI
The digital landscape is evolving rapidly. With the advent of AI, every sector is witnessing a revolution, including…
By Louise North
14 Top UX Tools for Designers in 2024
User Experience (UX) is one of the most important fields of design, so it should come as no surprise that there are a…
By Simon Sterne
What Negative Effects Does a Bad Website Design Have On My Business?
Consumer expectations for a responsive, immersive, and visually appealing website experience have never been higher. In…
10+ Best Resources & Tools for Web Designers (2024 update)
Is searching for the best web design tools to suit your needs akin to having a recurring bad dream? Does each…
By WDD Staff
3 Essential Design Trends, April 2024
Ready to jump into some amazing new design ideas for Spring? Our roundup has everything from UX to color trends…
How to Plan Your First Successful Website
Planning a new website can be exciting and — if you’re anything like me — a little daunting. Whether you’re an…
By Simon Sterne
15 Best New Fonts, March 2024
Welcome to March’s edition of our roundup of the best new fonts for designers. This month’s compilation includes…
By Ben Moss
LimeWire Developer APIs Herald a New Era of AI Integration
Generative AI is a fascinating technology. Far from the design killer some people feared, it is an empowering and…
By WDD Staff