TIP PiwikPlugin is not installed on Foswiki.org.

PiwikPlugin

Server-side page tracking using Piwik

logo.png

This plugin lets you track page views using the Piwik web analytics services.

Piwik is the leading self-Hosted, decentralized, Open Source web Analytics Platform, used by 460,000 websites in 150 countries.

In most cases the JavaScript API is used on the client side to bring Piwik-based web analytics to your site. However browsers tend to block these additional third party cookies and services which then results in rather sparse data being collected.

Alternatively PiwikPlugin uses the REST api of Piwik to track page views on the server side. That is, your Foswiki server talks to a Piwik server informing it about things going on behind the scene.

There are a couple of advantages and disadvantages comparing client side vs server side page tracking:

  • measurements on the server are more reliable as they don't rely on the client to cooperate with regards to JavaScript and cookie settings
  • installing a Foswiki plugin is more standardized compared to injecting additional JavaScript to your site
  • page rendering times are captured on the server and propagated to te Piwik analyzer
  • custom site search tools like SolrPlugin can hook into the tracking process on the server in a reliable way
  • the Piwik API doesn't have to be exposed to the outside which would normally be the case for the browser to be able to contact it
  • some measures like screen size and browser plugins can't be recorded on the server
  • click overlays don't work without piwik-related JavaScript being added to the site

In short: the bulk of interesting data can be captured server side in a more reliable way while some minor features of Piwik aren't covered yet by data produced by PiwikPlugin.

Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. "Extensions Operation and Maintenance" Tab -> "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button. Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will not show up in the search results.

You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
cd /path/to/foswiki
perl tools/extension_installer <NameOfExtension> install

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See https://foswiki.org/Support/ManuallyInstallingExtensions for more help.

To finish installation, you'll have to configure at least:

  • the {ApiUrl} of your Piwik server, e.g. http://localhost/piwik/piwik.php
  • The {TokenAuth} to access advanced features (see the API menu on your Piwik server).
  • the {SiteId} of your Foswiki server; this is a numeric id of your sites configured in piwik itself
  • the {QueueDir} to spool tracked page views while being recorded by Foswiki

Note that you must use different SiteIds in each VirtualHost.cfg file in case you are using Foswiki:Extensions/VirtualHostingContrib, e.g.

$VirtualHost{PiwikPlugin}{SiteId} = 1;

Page impressions aren't recored to the Piwik server directly for performance reasons. Instead, they are spooled in a queue specified by the {QueueDir} configuration setting. Foswiki itself will write to that directory while the interim piwik_daemon has to be started which takes over responsibility forwarding the records to the actual Piwik server.

Foswiki < 1.2.0

To track rendering times on older Foswikis you need to apply below patch

--- a/lib/Foswiki/Request.pm
+++ b/lib/Foswiki/Request.pm
@@ -37,6 +37,16 @@ use Error    ();
 use IO::File ();
 use CGI::Util qw(rearrange);

+use Time::HiRes ();
+
+sub getTime {
+    my $this     = shift;
+    my $endTime  = [Time::HiRes::gettimeofday];
+    my $timeDiff = Time::HiRes::tv_interval( $this->{start_time}, $endTime );
+    return $timeDiff;
+}
+
+
 =begin TML

 ---++ ClassMethod new([$initializer])
@@ -69,6 +79,7 @@ sub new {
         remote_user    => undef,
         secure         => 0,
         server_port    => undef,
+        start_time     => [Time::HiRes::gettimeofday],
         uploads        => {},
         uri            => '',
     };

Dependencies

NameVersionDescription
LWP::UserAgent>=6.03Required.
Digest::MD5>=2.33Required.
URI>=1.59Required.
JSON>=2.53Required.
Filesys::Notify::Simple>0Required.
Foswiki::Plugins::TopicTitlePlugin>1.00Required for Foswiki < 2.2

Change History

28 May 2018 removed local implementation of TopicTitle and use Foswiki:Extensions/TopicTitlePlugin now
25 Sep 2017 fixed broken init scripts for piwik_daemon script
16 Dec 2014 ignore ssl certificate problems when contacting piwik on localhost
05 Dec 2014 use both either completePageHander or modifyHeaderHandler not to miss a page view
29 Aug 2014 added proper system init scripts; fully specify rest security
18 Mar 2014 added support for foswiki engines < 1.2.0
01 Nov 2013 final 2.0 release
18 Jul 2013 added tracking of outlinks and downloads
16 Jul 2013 added auto-start feature for the piwik comm server
15 Jul 2013 implemented queue manager for better tracking performance; improved control over pages and actions being tracked
14 Jul 2013 initial release

I Attachment Action Size Date Who Comment
PiwikPlugin.md5md5 PiwikPlugin.md5 manage 156 bytes 28 May 2018 - 13:38 MichaelDaum  
PiwikPlugin.sha1sha1 PiwikPlugin.sha1 manage 180 bytes 28 May 2018 - 13:39 MichaelDaum  
PiwikPlugin.tgztgz PiwikPlugin.tgz manage 22 K 28 May 2018 - 13:38 MichaelDaum  
PiwikPlugin.zipzip PiwikPlugin.zip manage 28 K 28 May 2018 - 13:38 MichaelDaum  
PiwikPlugin_installerEXT PiwikPlugin_installer manage 5 K 28 May 2018 - 13:38 MichaelDaum  
Topic revision: r12 - 28 May 2018, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy