Results tagged “piwik”

Piwik and Elgg

While Google Analytics may be the most popular analytics service, there are times when you want to use your own hosted solution (intranet, control over data). Piwik is a great open source package that provides an impressive set of tools and a very nice look and feel. Using it with Elgg is extremely easy. You can write a plugin to do this in a few minutes as Elgg provides an analytics view in the footer that can be extended.

This is all it takes:

  1. Install Piwik

  2. Create your Elgg plugin skeleton

  3. Create a view to hold your Piwik javascript code - in this case piwik/analytics

  4. Register a callback for the init:system event

  5. In the callback extend the footer/analytics view

  6. Install and activate the plugin

The structure of this very simple plugin looks like this:

Plugin Structure

You can download it here.

Piwik generates its URLs used in links and forms based on data in $_SERVER[]. If you are using a reverse proxy in front of your web server, the incoming request URLS are for the internal server. This results in the people from the outside getting 404 errors after the getting the initial landing page.

To work around this, I was able to use Piwik's boostrap.php file. This is loaded first for any Piwik page. I added some code in there to rewrite PHP's $_SERVER[] parameters to match the original request to the proxy. The variables I had to set were