Build Your Own Web Measurement Application: Technographic Data

One of the more interesting things that web measurement applications are able to do is help you understand the geographic distribution of your visitors. In this hack, we leverage a freely available geo-targeting database and add IP-based visitor geography reporting to the build your own application.

In this hack, we show how to extend our example program to report the number of visitors from each country [Hack #78] . This is often known as geo-location, geo-targeting, or geographic segmentation. The way it works is that certain companies sell large databases mapping numerical IP addresses to countries, or even to regions and cities. The databases can never be 100% accurate because the way ISPs route data through their internal networks is unpredictable. But, at least at the country level, they give a reasonably good idea.

Installing IP::Country and Geography::Countries

One advantage of using Perl is that when you want to do something like this, someone’s probably already done it for you and built it into a Perl module. In this case, we’ll use MaxMind’s Geo::IP module. MaxMind’s basic country database is free, although they do sell more accurate and more detailed databases.

To download and install the Geo::IP module, you need to follow the instructions at http://www.maxmind.com/app/perl. Under Unix or Linux, you have to download and install the GeoIP C library and the Geo::IP Perl modules from that page. Under Windows, ...

Get Web Site Measurement Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.