For Web site owners who rely on advertising revenue to keep their sites alive, every click is valuable. And since Web users have become largely immune to ads after the excessive pop-ups and in-your-face animations of the past year, anything that attracts their attention automatically gives your site an edge over the competition. What could be better, then, than ads that are localized to the user's region and thus directly relevant to him or her?
Consider the following example: A user logging in from Italy might have little interest in an ad for cheap pizza, since she lives in the country that invented it. But show that same user an ad extolling the fuel efficiency of the latest Fiat city car, and you're quite likely to get a click, since many Italians drive that brand of automobile. Localized advertising, if used wisely, can significantly help a Web site raise its clickthrough rate and hence its revenue.
Getting IP-to-country mapping with MaxMind's GeoIP
To deliver an ad banner customized to a user's country of origin, you need to first obtain the user's IP address and map it to a country. IP address blocks are assigned to a country by the Internet Assigned Numbers Authority (IANA) and its delegates.
A number of organizations offer mapping services to bring all the IP-to-country mapping information into an easy-to-use format. The one we're going to explore is MaxMind's GeoIP, mostly because it offers a usable free version. It's not as accurate as the paid version, but for the purposes of experimentation, it works well enough. Click here to learn how to use GeoIP.
A simple geo-targeted MySQL database with GeoIP and PHP
Okay, now that you've got GeoIP installed and working, how can you use it to deliver those geo-targeted ads? You can set up a little MySQL database to store a mapping of ads to country codes, and then use GeoIP to deliver the right ad.