Serving Location-Specific Content with IP Geolocation

Geolocation is the process of finding the geographical location of a website visitor. This article explains how finding the continent, country, region and city of website visitors enables websites to serve location-specific content.

1. Introduction

You can find the geographical location of your visitors using the IP address of their computer with a geolocator. Geolocators look up the geographical information for an internet protocol (IP) address in a database.

2. Country Geolocation

Geolocators typically return the following country information for an IP address:

  • two-letter country code (eg. GB);
  • three-letter country code (eg. GBR); and
  • country name (eg. United Kingdom).

The two-letter country code follows ISO 3166-1-alpha-2; the three-letter country code follows ISO 3166-1-alpha-3; and the country name is the official short name in English according to ISO 3166-1. Learn more about ISO 3166 at Wikipedia and at the ISO.

Country geolocation is the most accurate form of IP geolocation with an accuracy of about 95%. Once you’ve got the two-letter country code, you can access other country-specific information.

3. Continent Geolocation

Once you’ve got the two-letter country code, you can also identify the continent. Geolocators typically return the following continent information for an IP address:

  • two-letter continent code (eg. EU); and
  • continent name (eg. Europe).

Geolocators often use the following two-letter continent codes and continent names:

AS Asia
AN Antarctica
AF Africa
EU Europe
NA North America
SA South America
OC Oceania

Wikipedia lists the countries in each continent.

Because the continent of an IP address is identified using the country of the IP address, continent geolocation has the same high accuracy as country geolocation, which is about 95%.

If you’re an Amazon Associate you’ll want to serve links to the most appropriate Amazon website. For example, you might serve links to Amazon.co.uk for European visitors and serve links to Amazon.com for everyone else. Find out more about Amazon geolocation.

4. Region Geolocation

A region is an administrative division of a country that is larger than a city. Examples of regions include:

Geolocators that can be more specific than the country often return the region of an IP address.

5. City Geolocation

Some geolocators return the city of an IP address. Unlike country geolocation, which has an accuracy of about 95%, city geolocation has an accuracy of about 75%. For example, if you live in a small town or village, a geolocator will often return the name of the nearest large city. Once you’ve got the name of the city, you can serve city-specific content.

6. Amazon Geolocation

I’ve developed two sets of rules to identify the appropriate Amazon website for an IP address. The first set selects an Amazon website from all the Amazon websites with an Associates program. The second set of rules selects an Amazon website from the Amazon websites written in English. Using these rules, an Amazon geolocator returns the two-letter ISO 3166-1-alpha-2 code of the country with the selected Amazon website.

Geolocating all Amazon websites

Using the first set of rules, an Amazon geolocator selects the Amazon website of the visitor’s country if that country has an Amazon website with an Associates program; otherwise, the geolocator selects Amazon UK for visitors in Europe and selects Amazon USA for visitors in all other countries. The following table summarises these selections.

France Amazon.fr FR
Germany Amazon.de DE
Rest of Europe Amazon.co.uk GB
Japan Amazon.jp JP
Canada Amazon.ca CA
Rest of the World Amazon.com US

Geolocating English-Language Amazon Websites

Using the second set of rules, an Amazon geolocator selects Amazon UK for visitors in Europe, selects Amazon Canada for visitors in Canada, and selects Amazon USA for visitors in all other countries. The following table summarises these selections.

Europe Amazon.co.uk GB
Canada Amazon.ca CA
Rest of the World Amazon.com US