Open-Source Web Analytics Tool: Piwik Installation and Configuration Guide

piwikweb analyticsself-hosted statisticsgoogle analytics alternativereal-time website tracking
Published·Modified·

Piwik is a web statistics tool developed using PHP and MySQL that allows for real-time website traffic analysis. Comparable to Baidu Statistics, CNZZ, and Google Analytics, Piwik can be hosted on your own server.

Piwik Admin Interface

Download and Installation

Before reading this article, it is assumed that you have a basic understanding of website setup. Therefore, the detailed setup process will not be described; instead, this guide summarizes common issues encountered during installation.

The installation process is straightforward, and the official documentation is detailed. However, note that Piwik requires the shell_exec function. This function is often disabled by default in many environments. You must modify the php.ini file to enable shell_exec and restart your web server.

Setting Up Chinese Language

Piwik supports multiple languages. The default interface is in English, but it can be changed to Simplified Chinese in the backend.

Path: Personal > Settings > Language > Select "Simplified Chinese" and save.

Piwik Language Settings

Using HTTPS

To prevent traffic hijacking and ensure security, it is recommended to use HTTPS encrypted access. In addition to configuring the correct SSL certificate on your web server (e.g., Nginx), you must add the following line to the [General] section in your site directory's config/config.ini.php file:

assume_secure_protocol = 1

If you are unsure how to apply for an SSL certificate, refer to the following articles:

Obtaining Real IP Addresses

If your website or Piwik is using a CDN, you may find that the Piwik backend statistics only show CDN node IP addresses, which is not ideal for analysis. The official solution is available in the article: How to Get Real IP Addresses in PIWIK.

IP Statistics

By default, Piwik's IP statistics are inaccurate and can only identify the country, not the city. The official solution is to use a GeoIP database to improve accuracy.

  1. Download the GeoIP Database: GeoLiteCity.dat.gz
  2. Place the database in the site's misc directory.
  3. Unzip the database using the command: gzip -d GeoLiteCity.dat.gz
  4. Enable GeoIP support in the Piwik backend: System > Geolocation > GeoIP (Php).

Piwik GeoIP Settings

Summary

You can now add a site in the Piwik backend and insert the provided JavaScript code into your website to achieve powerful tracking capabilities similar to Google Analytics. Piwik is particularly suitable for small to medium-sized websites and solves the issue of slow loading times for Google Analytics in China.

Piwik also offers a mobile app, allowing you to view real-time data on your phone anytime.

However, during use, you may notice many "keyword not defined" entries in the search source statistics. This is a common issue reported by many users, not just myself. The explanation is that no statistics tool can be 100% accurate regarding search terms, possibly due to competition and mutual blocking between services.

Piwik Official Website: https://piwik.org/