The most current version is 1.1, released 2011-08-17.


Piwik is an open source real time web analytics software that aims to be like Google Analytics and its use is considered appropriate to German dataprotection laws.
In order to activate Piwik one has to add a small Javascript snippet to all pages that should be monitored. With tons of static HTML pages this can be quite challenging or for a test you might not even want to fiddle with the templates of a CMS.

This is the situation where addpiwik will help you. Using the apache webserver module mod_ext_filter one can modify the HTML code on the fly, injecting the Piwik Javascript code snippet right before the closing </body> tag.

Apache configuration:

ExtFilterDefine add-piwik mode=output cmd="/path/to/addpiwik" intype=text/html outtype=text/html \

Please note that there are no quotes allowed for the parameters, except for cmd.

Now we have an output filter called add-piwik that is only active for data with a content type of text/html (so it won't be used for eg. images) and the environment variable PIWIK_IDSITE has to be set for the filter to be active.

Activate the filter for a directory:

<Directory /var/www/html/piwiktest/>
    SetEnv      PIWIK_URL ""
    SetEnv      PIWIK_IDSITE "1"
    SetOutputFilter add-piwik

The http:// or https:// part must be omitted in PIWIK_URL, as the Javascript snippet checks for the protocol used and adds the correct prefix itself.


  • for the python version no additional python modules are required
  • for the C language version I was lazy and used the GNU getline() function. All recent versions of Linux should be fine with that.
    To my knowledge FreeBSD version 8.0 and greater also have that function in their standrd C library now.


The software is licensed under a BSD style license. See license.txt.

To install the program it should be sufficient to either

   $ chmod 755
   $ cc -o addpiwik addpiwik.c

and then copy it to whatever location you like.


Markus Stumpf <>


1.1 - 2011-08-17
Fixing some stupid bugs. Thanks go to Tetti and Andre Dalle.
1.0 - 2010-09-30
initial release
Valid XHTML 1.0 Transitional Valid CSS! BY- CC-3.0 Copyright © 2010 Markus 'Maex' Stumpf
created: 2010-08-22 09:15:49 GMT+2
last modified: 2011-08-17 20:29:06 GMT+2