How To Easily Implement Custom GeoTargeting
Affiliate Marketing, Programming, Web Development July 23rd, 2007If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
GeoTargeting can be very useful in the world of internet marketing, but many people just don’t take the time to set it up properly. I have been using a GeoTargeting system for about two years now, and it has contributed thousands of extra dollars to my bottom line.
In this article, I am going to give you a couple examples of how I have taken advantage of GeoTargeting, and then show you two ways to implement your own custom system.
Examples Of How I Have Used GeoTargetting
I have used GeoTargeting for many different internet marketing projects including standard ad serving, payment processing, and affiliate marketing. With respect to affiliate marketing, some CPA networks will filter traffic for you, but they don’t always do what will make you the most money.
One affiliate offer that I promoted in the past was available as multiple offers, each compatible with different countries. The catch was that different affiliate networks had different payouts for each country. For example, ‘affiliate network 1′ paid the highest for US leads while ‘affiliate network 2′ paid the most for Canada leads. If I had simply sent all traffic to ‘affiliate network 1′, they would have filtered it for me, but I would have been leaving a lot of money on the table.
A second example of my GeoTargeting is when I had a Yahoo Publisher Network account. They only allowed publishers to serve their ads to US traffic; serving ads to other countries could get your account banned. In this case, GeoTargetting was mandatory. Had I not had a system in place, I would have been stuck with AdSense, which paid much less at the time.
Another benefit of using GeoTargeting, when applied to PPC traffic, is that you are actually ‘cloaking’ your landing pages. If there is something you want to do on your landing page, but the PPC engine’s TOS doesn’t allow it (or you don’t want to deal with QualityScore issues), at least you can do it on the non-US (or non-California) versions. Unless the spiders and/or editors are based in those countries (or are using proxies), they will never know the difference
Implementing Your Own GeoTargeting System
The biggest requirement for a GeoTargeting system is to have a database that matches IP addresses with their geographical locations. There are a couple methods for achieving this, some complicated and some simple, but the method you choose depends entirely on your individual needs.
Method 1: Self-Hosted Solution
The most reliable (and fastest loading) solution would be to have the database hosted on a server that you control. You wouldn’t have to worry about the database going offline or becoming too busy (unless, of course, your web site suffered from these problems as well). This, unfortunately, is also the most complicated and/or expensive solution, and requires that you are responsible for keeping your database current.
I started out using self-hosted GeoIP databases exclusively, and still do use them on some of my projects. I would recommend downloading the GeoIP Lite database from MaxMind because it is free and updated on a monthly basis. They claim that it isn’t as accurate as their paid database, but it has been good enough for me.
Getting GeoIP data into your database is actually a pretty easy process and only requires a single table. Then, when a visitor loads a page on your website, you can convert their IP address to a value in the database (using a custom algorithm) and match it up with what country they are in. Here is the PHP script I use:
// connect to the database
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("databasename", $db);
// get the user ip address and convert to an array
$ip = $_SERVER['REMOTE_ADDR'];
$ip_arr = explode(".", $ip);
// convert the ip address to an ip number
$ip_num = 16777216*$ip_arr[0] + 65536*$ip_arr[1] + 256*$ip_arr[2] + $ip_arr[3];
// get the country code
$result = mysql_query("SELECT country FROM geo_ip WHERE $ip_num BETWEEN begin_num AND end_num");
$row = mysql_fetch_array($result);
$country = $row['country'];
The “$country” variable will now contain the user’s country code (US, GB, CA, etc) which you can then use to determine what content to show or where to redirect them.
For a better explanation on how to use the database, read the official instructions.
Method 2: Remotely Hosted Solution
If the previous example was too complicated, I have an easy, cut-and-paste solution for you. I just found out about this website a few months ago, but have gotten a lot of use out of it. HostIP.info offers free API access to a GeoIP database that they host, no strings attached.
The API is extremely easy to use. Just pass an IP address to one of their web pages and they will return the requested information. Here is an example PHP script that you can use to get the same results as with the previous example:
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$_SERVER['REMOTE_ADDR']);
And that’s without having to set up a custom database or do any other prep work!
In addition to getting the visitor’s country code, you can request other information such as their country name, city name, lattitude, longitude, and a graphic of their national flag
Getting these values, however, will require a few extra lines of programming to parse the output text into individual variables.
The downside of this method is that, because you are sending a request to another server, it can increase the time it takes for your pages to load. One way to counteract this would be to only execute the check once per visitor, storing the information as a cookie on their computer.
What To Do With The Country Code
If you have any programming knowledge at all, you will have already figured out what you can do once you have the visitor’s country code. For those of you who are not familiar with a programming language, here is an example.
Lets say I have three pages set up. One page is specifically designed for United States visitors, one is for Canada visitors, and the last page is for all other visitors. I would use a simple “if-then” statement that checks the country code and sends the visitor to the correct page. Here is the PHP code for this example:
if ($country == 'US') { header('Location: /united_states.html'); }
else if ($country == 'CA') { header('Location: /canada.html'); }
else { header('Location: /other.html'); }
As you can see, it isn’t very complicated.
Conclusion
Although GeoTargetting isn’t always applicable in internet marketing, there are many situations where it does make a difference. If there is an area in your business that would benefit from GeoTargeting, but you haven’t set it up because you didn’t know how, now is the time.
If nothing else, at least test using custom landing pages tailored to users in specific cities, states, or countries depending on their individual cultures and tastes. It could possibly boost your conversions if the visitor feels like the page was made just for them ![]()
July 25th, 2007 at 11:31 am
I wrote about using MaxMind a bit last year (http://www.iamjacksdesign.com/blog/geolocating-ip-addresses/) but I went with the web service over the free database.
At that time, the free database was pretty inaccurate for my own needs. If you were just going for a user’s country and maybe even state it was fine, but down to the city level it was pretty out of whack with reality.
Again, this was back in November of ‘06 so there’s a good chance the free database has shown some improvement with it’s accuracy.
July 25th, 2007 at 10:34 pm
I’ve never tried any of their paid services, just the free database
I don’t use the MaxMind database for city/state level tracking, just for countries. It has been about 99% accurate on that level when compared to AdWords and affiliate network geotargeting.