Self-Hosting Your Own Analytics Server With Piwik

Final product image
What You'll Be Creating

Piwik may be the most polished open source analytics tool you've never heard of. Not only has it had more than two million downloads, it has a rich set of features and excellent documentation. This tutorial will describe how to install and use it to track web traffic to your own sites.

If you prefer to pay to have someone else run it for you, they offer several cloud-based options. Piwik offers a 30 day free trial with $65 monthly pricing afterwards. There's also a community of paid consultants you can hire to assist you.

Benefits to Hosting Your Own Analytics

I've been a long-time user of freemium, cloud-service analytics provider Statcounter. I like being able to see specific user activity and IP address traffic. While Google Analytics doesn't provide this information, Statcounter lacks many of the features that Google Analytics provides for free.

Enter Piwik, a mature, well-documented, full-featured open source analytics product written in PHP; it even offers free mobile applications for iOS and Android. 

Piwik Offers a Mobile App

The team has upcoming plans to offer a tool to migrate Google Analytics data to Piwik in 2015.

Installing Piwik on Your Own Server

Piwik runs on any modern LAMP-based server configuration. If you'd like, you can begin with my generic Ubuntu LAMP installation here.

Then, follow my installation instructions below and/or watch the installation video:

First, let's download the open source Piwik code and create a web directory for your dashboard:

Change the ownership and permissions appropriate to your web server:

Create an Apache site configuration file and paste the Virtual Host definition below into it. Then, enable the site.

Paste in and customize the virtual host definition for your Piwik site as shown below:

Setting Up Piwik

You can follow the Piwik five minute installation guide if you'd like more details. The installation wizard you should see on your site is quite simple:

Piwik Installation Wizard Welcome

It performs a system check, which should pass if you followed my LAMP configuration guide:

Piwik Installation Wizard System Check

Enter in the database permissions that you created from the configuration guide—when you created your MySQL database:

Piwik Installation Wizard MySQL Database Setup

You should see this:

Piwik Installation Wizard Database Created

Specify your administrator or superuser login credentials:

Piwik Installation Wizard Superuser

Now, you can add your first website to track:

Piwik Installation Wizard Add Your Site

Keep in mind that the site isn't actively tracking yet. We'll do that below.

If you log out, you'll be greeted with the Piwik sign-in. Enter your administrative credentials chosen above:

Piwik Sign In

Enabling Tracking From Your Sites

There are a couple of ways to enable tracking on your website.

Embedding JavaScript

Just like with Google Analytics, you can paste the Piwik JavaScript into your website code:

Piwik Tracking Code in Javascript

WordPress Plugin

Or, you can install the WP-Piwik plugin:

WP-Piwik Plugin for WordPress

Next, visit your Piwik API settings and copy your authentication token—just the parameter value (mine is blacked out below).

Piwik API Key

Visit the WordPress WP-Piwik Settings page and provide your Piwik URL, the domain you set up to host Piwik, and the auth token. 

WP-Piwik Plugin for WordPress Settings

Don't forget to visit the Tracking tab under settings to turn on the tracking code on your WordPress site:

WP-Piwik Plugin for WordPress Tracking

The Piwik Dashboard

You should be able to see data coming in immediately from the real-time dashboard panel:

Piwik Real Time Visitor Panel

Once Piwik's been collecting data for a few days, you should see something like this in the Piwik Dashboard when you log in:

Piwik Dashboard

All the sites you've added can be viewed at a glance:

Piwik All Sites

Here's what a summary of traffic by page title looks like:

Piwik Visitor Traffic by Page Title

Here's a visitor log for all traffic:

Piwik Visitor Log

And Piwik has a variety of other features such as device, operating system and browser statistics:

Piwik Devices and Operating Systems

The Piwik administration settings are well designed and very thorough. It's unusually good for an open source project:

Piwik Settings

Piwik Mobile Applications

There are also free Piwik mobile apps available at the AppStore and Google Play, so you can keep up with your site traffic on the go more easily:

Piwik iOS and Android Mobile Apps

Special Considerations

Piwik has a wide variety of capabilities. Here are a few things you may wish to update in your own system.

Anonymizing IP Addresses

You can change how much of IP addresses Piwik collects—this affects the relative privacy of your users:

Piwik Anonymize IP Addresses

Excluding Your Visits

You can set a cookie on your browser to prevent Piwik from adding traffic of your own editing and browsing from being counted:

Piwik Exclude Your Visits

Rolling Up Database Logs

You can also set up Piwik to automatically roll up its logs and reports, to prevent the database from growing too large over time:

Piwik Rollup Logs

Where to Go From Here

Hopefully you've found Piwik useful and interesting. The team has a variety of ways for you to learn more and engage with its community:

I've been impressed with the clean design and relatively robust feature set provided by this free, open source project.

If you have any questions or suggestions, please post them in the comments. If you'd like to keep up on my future Tuts+ tutorials and other series, please visit my instructor page or follow @reifman.

Tags:

Comments

Related Articles