Getting web visits data for analytics with Javascript, Python and GeoIP


$ apt-get install -y geoip-database 
$ pip install python-dateutil pygeoip

We are going to parse the navigator data to obtain the language, browser, operative system, screen resolution, density of pixels of the screen and a boolean to define if the user is using a touch device. This data will be POSTed to be analyzed and stored (in this example in the path '/analytics').

The Javascript code:

Server-side geo data

I'm going to use Tornado and Cassandra, the code is pretty straightforward so you can easily extrapolate it to your preferences (let's say Django and PostgreSQL, as an example).

You will need to download the GeoLite City database in your application data root (defined as settings.DATA_ROOT).

The Python code:

Originally published at on February 11, 2015.