Piwik and WordPress on Synology DSM
January 10, 2016
This is only my second post and I started only 3 weeks ago, but I have been wondering ever since about one question: Would people actually come to visit this blog?
The itch
To me this is an intriguing question. It made other questions pop up as well. Would visitors come along all by themselves? Would I need to promote this blog? Where and how to promote it and how to determine whether my promotion efforts are successful or not? So here it was, the itch I wanted to scratch.
The scratching
To start finding answers to above questions (and thus scratching that itch), I decided to give Piwik a try. Piwik is an open source analytics platform and as such is more than capable to answer my questions (and surely many more). Head over to their website to find out more. Besides Piwik being able to answer my questions, the second reason I decided to go with Piwik was one of convenience: It is available on Synology DSM, which I am currently using to run this blog, Jenkins on Tomcat, a little NodeJS app to generate my CV website etc.
How to scratch that specific itch
So let me explain how to get Piwik installed and setup to track your WordPress blog, but beware: I am using both applications on my Synology Diskstation, which are both available in the DSM Package Center, so please do not expect me to explain how to manually install them. There is documentation by the specific projects for that. Besides, on DSM you can one-click-install Piwik and WordPress from DSM Package Center and both have click through setups. They both require PHP and a MySQL type DB, like MariaDB, which is also available in Package Center. If you require help installing Wordpress on your DSM, have a look at this. WordPress setup is quick and easy. Similarly for Piwik after you installed it from DSM Package Center, it appears in the DSM app drawer and by clicking that newly created Piwik icon a new browser tab opens with the Piwik setup wizard. However, there might be a few things to note about Piwik setup. The setup step 3. “Database Setup” requires an existing database user and it’s password and the user needs permission to create a new database instance and tables within that instance. Keep that in mind when providing the user credentials. You might be able to create a specific database instance and a specific user with the required privileges beforehand, but I went for the lazy (and potentially unsafe?) option. In step 5. “Super User” you provide a new username and password that you want to use to administer your Piwik installation. This is not related to the credentials provided in step 3, so do not let the setup wizard confuse you. In step 6. you need to provide your blog’s URL. This will add your blog to Piwik, but tracking will not be setup for you at that point. We will do this later, don’t worry. Step 7. illustrates the required tracking code. Since we want to track our WordPress visits we won’t add this code to the blog ourselves, but will instead use the WP-Piwik plugin to handle this for us. In my case step 8. showed the option to anonymize the last 2 bytes of visitor’s IP addresses to comply with German privacy laws. I guess Piwik determined that this blog must be “from Germany” based on the website timezone defined in step 6. They did not provide any reference to a law paragraph requiring you to do so, but I did choose to adhere. Piwik is now installed, setup and ready to go. Now we head over to our WordPress dashboard to install WP-Piwik. You obviously need to be logged in for this, so head over to the dashboard (address should be something like http://yourDomain/wordpress/wp-admin), log in with your WordPress user and go to “Plugins” -> “Add New” and search for WP-Piwik. Click on “Install Now” and on “Activate Plugin” afterwards. Then we setup WP-Piwik (“Settings” -> “WP-Piwik” on the left hand dashboard menu) to connect it to our Piwik instance. For Piwik mode I chose self-hosted PHP API, because I have both WordPress and Piwik installed on the DiskStation. In this case Piwik path is /volume1/web/piwik. The auth token is unique. To get your auth token, log in to Piwik, click at your user name (top right) and click at “API” (left sidebar menu) as described here. We leave auto config checked, so that it will automatically choose our blog from our Piwik sites by URL. Remember Piwik setup step 6, where we added our site by URL. That is it and you can click “Save changes”. If successful, something like this should show up: WP-Piwik 1.0.5 is successfully connected to Piwik 2.11.2. You are running WordPress 4.4 But do not be fooled here! We have only finished the setup needed by the plugin to interact with your Piwik instance! We still need to enable tracking by making the plugin add the required tracking code to our blog so click “Enable Tracking” and select an option for “Add tracking code”. I chose “Use js/index.php”, because it supports conditional-GET and Last-Modified, so piwik.js can be cached by the browser and it supports deflate/gzip compression, shrinking the data transfer to 8K, which is described here. Compression and cache support sounds nice, doesn’t it? Proxy support is not interesting for me, because I don’t mind that people know where my Piwik installation is. Circumvent browser-based privacy filters is also unimportant since I want to respect visitor’s do-not-track preferences, which was available as an option during Piwik setup step 8. Tracking code preview and noscript code are empty, but don’t bother about that for now. It will update as soon as you save your settings and the tracking code gets added to your site. There are a lot of other options to decide what to track and what not. I want to track search, 404, enabled annotations, track RSS and filter WordPress admin, editor and author visits, because I don’t want to count my own visits when working on my blog. When you are done, click “Save changes”, which updates the code previews.
The relief
We have installed Piwik, added our WordPress blog to it and added the tracking code to our blog with the help of WP-Piwik. This means we are all set up to track our blog visitors, so let us test this already! To “fake” a visit I started an incognito browser session and visited my blog and there it was: Both Piwik and WP-Piwik displayed the visit in all it’s glory and with quite a lot of data: The visitor’s device operating system, the browser they used and the display resolution they viewed your page with along with their geographical location but wait: Why is my visit record saying I visited my blog from the US?
Polishing
My first visit’s IP was recorded in an anonymized form, which we decided to do so in Piwik setup step 8., but that is no reason to claim that the visit came from the US when it actually came from Germany. Luckily, this is fixable and the fix is quick and easy. Login to Piwik, click on “Administration” at the top right and choose “Settings” -> “Geolocation” in the menu on the left. There you find easy to follow instructions on how to setup accurate geolocation by switching from the default to the GeoIP (Php) location provider. In essence you simply download the GeoLiteCity database and copy that file into /volume1/web/piwik/misc on your diskstation. Once you have done so, you can activate the GeoIP (Php) location provider and instantly see the results on the right and also compare the geolocation determined by the different providers. For further information about improving the recorded geolocation you can check out the Piwik FAQ. Now that we have switched to an accurate location provider, we will have Piwik record the correct location of our visitors. However this will not change/update the location of past visits, like our “fake” test visit.
Wrapping up
It is nice to have both Piwik and Wordpress available as packages for the Diskstation. The installation is quick and easy and with the help of the WP-Piwik plugin you can easily connect your blog to Piwik and start tracking you blog visitors to get an idea about how popular your blog is and to get the data you need to actually improve it. To this end, let’s see how I can grow my reader base, get feedback and make my blog become a place of discussion and learning.