Piwik for this blog #################### :date: 2014-02-18 08:00 :tags: piwik, docker, pelican I was looking for a simple analytics tool for this blog. As everyone seems to be using **piwik** and everyone loves **docker** for rapid deployment. As i am always short on resources on all my machines i decided to deploy piwik on another of my VMs which is ``mediengewitter.krebsco.de`` instead of directly on ``euer.krebsco.de`` Again it was a case of 'how-hard-can-it-be?'. Turns out everything is much harder than expected. As always this this is the digest of some hours work. Installing piwik in docker ========================== After testing out all kinds of non-working Dockerfiles, this is what worked for me: .. code-block:: bash git clone https://github.com/makefu/docker-piwik.git piwik cd piwik ./build # if you want persistence, see: mkdir -p /media/ext/piwik/{www,mysql} cat README Running piwik ============= Because docker handles it's own network, the docker image port 80 must be forwarded to the host (i use 10000). Also i want data persistence via exported filesystems. .. code-block:: bash docker run -p=10000:80 -d \ -v /media/ext/piwik/www:/var/www \ -v /media/ext/piwik/mysql:/var/lib/mysql piwik # or ./run Adding piwik to pelican ======================= Integration of piwik tracking to pelican **should** be straight forward, just add the following to your ``pelicanconf.py``: .. code-block:: python PIWIK_URL='mediengewitter.krebsco.de:10000' # first piwik site is always id 1 PIWIK_SITE_ID=1 Bit nothing seemed to be happening, turns out my theme of choice does not support piwik so i had to add this feature explicitly to the skin (by stealing the code from another theme). I created a pull request for my code: https://github.com/getpelican/pelican-themes/pull/195 . If it will never be merged, use my repository for themes: .. code-block:: bash cd git clone git@github.com:makefu/pelican-themes.git -b add-piwik-to-gum themes Add piwik to another skin ========================= If you are using another skin without piwik integration, this is basically what you need to do: 1. Add piwik.html to '``/templates``' .. code-block:: html {% if PIWIK_URL and PIWIK_SITE_ID %} {% endif %} 2. Add this line somewhere near the end but before to '``/templates/base.html``': .. code-block:: html ... {% include 'piwik.html' %} ...