Note: this article is out of date, as Piwik has become Matomo
Piwik is an open source web analytics tool developed in PHP that can be deployed to a server or run from their cloud service.
I wanted to try this tool out as an alternative to Google analytics, with Piwik giving you full control of all accumulated data and better privacy options for visitors to your tracked sites.
To install Piwik, it is recommended to deploy it to the root of the webserver directory which is normally /var/www .
However with ForkCMS already occupying that location and with its .htaccess preventing subdirectory access I could not simply use that space. So I decided to emulate the way PHPMyAdmin is accessible through a seperate directory using an alias.
e.g. www.foobar.com/phpmyadmin ---> /var/lib/phpmyadmin
To do this I needed to setup a config on Apache.
# analytics config file allows redirection of /analytics
Alias /analytics /var/analytics
# Disallow web access to directories that don't need it Require all granted
Once created you can enable this config by using this command in the shell.
service apache2 restart
Creating a directory called analytics in /var , then it is just a case of downloading and installing Piwik from that folder.
This can be found at /var/www/src/Themes/<themename>/Core/Layout/
Then at the bottom of the Default.tpl file I added the following lines before the </body> tag.
<noscript><p><img src="http://loosebruce.co.uk/analytics/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
After that, all you need to do is clear the site cache and the site tracking will start working.