Tag Archives: piwik

How to enhance geolocation in Piwik

If you decide to use Piwik for you website statistics, here is a procedure to enhance the accuracy of geolocation.

We will configure our Linux server (Debian or Ubuntu) with PECL that is recommended method (only if you have a dedicated server and you can configure it as you want, for a shared one, use PHP method instead).

Connect to it with SSH et install libraries and tools :

apt-get install php-pear php5-geoip php5-dev libgeoip-dev
pecl install geoip

We are going to install the database. When libraries are installed, go to Piwik > Settings > Geolocation, and at the bottom of the page, you can download the free database. If you have an error message, you can download it mannually at this address, you will have to use wget in SSH by example, then move the file in <piwik path>/misc. Think to rename it from GeoLiteCity.dat to GeoIPCity.dat.

Last step is enable it in the server. Library installation probably configured PHP automatically. Modify the needed file (/etc/php5/fpm/conf.d/20-geoip.ini or /etc/php5/conf.d/geoip.ini by example) to get :

extension=geoip.so
geoip.custom_directory=<chemin piwik>/misc

Restart apache, or fpm, or anything else, and go back to Piwik administration, et check PECL that should mention installed in green text.

Piwik GeoIP PECL installé

Think to setup automatic updates (monthly by example) in adding the link above in URL field.

Piwik Configurer les mises à jour automatique GeoIP

If you want to test update, force Piwik cron in going to http://<PIWIK URL>/misc/cron/archive.php?token_auth=<TOKEN> address replacing <TOKEN> by your super user token you will find in Users page.

Documentation