Extension:Piwik Integration

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
Piwik Integration
Release status: stable
Implementation User activity
Description Inserts Piwik script into pages for tracking
  • Isb1009,
  • Youri van den Bogert,
  • DaSch,
  • Seb35
Latest version 3.1.0 (2018-02-07)
MediaWiki 1.25+
PHP 5.4+
Composer mediawiki/piwik-integration
License GNU General Public License 2.0 or later
  • $wgPiwikIDSite
  • $wgPiwikURL
  • $wgPiwikIgnoreSysops
  • $wgPiwikIgnoreBots
  • $wgPiwikCustomJS
  • $wgPiwikUsePageTitle
  • $wgPiwikActionName
  • $wgPiwikDisableCookies
  • $wgPiwikProtocol
  • $wgPiwikTrackUsernames
  • $wgPiwikJSFileURL
Hooks used
Translate the Piwik Integration extension if it is available at translatewiki.net
Check usage and version matrix.

The Matomo/Piwik Integration extension inserts your Matomo (formerly Piwik) tracking code to the bottom of every page. It can exclude the views of the users with 'bot' privileges (bots) and the 'protect' privileges (sysops).

This exension is based on extension Google Analytics Integration by Tim Laqua.

Warning Warning: This extension will be renamed in the second half of 2018 to Extension:MatomoAnalytics given Piwik changed its name on January 2018 (more explanations). There will be the following changes:
  • the extension itself will be renamed "Matomo" instead of "Piwik Integration" or "Piwik";
  • the parameters $wgPiwik… will be renamed $wgMatomo… (but the former ones will still work);
  • the Composer package will be renamed to "mediawiki/matomo" with a redirect from the old name;
  • it will become mandatory to activate the extension with wfLoadExtension( 'Matomo' ); in LocalSettings.php (no more autoloading with Composer or with a require_once).


  • MediaWiki 1.25+ (tested up to MediaWiki 1.30)
  • Piwik 0.4+ with the site configured

Installation instructions[edit]

  • Download and place the file(s) in a directory called Piwik in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'Piwik' );
  • Configure the Piwik URL and site-id by setting up the following variables below this extension's call:
$wgPiwikURL = "piwik-host.tld/dir";
$wgPiwikIDSite = "piwik_idsite";

Make sure to set $wgPiwikIDSite to the ID of your site in Piwik. For the first site, this ID will usually be "1". In Piwik, click on the "Administration" link in the top menu and go to the "Websites" page. In this page you will find the list of all websites. The website ID is on the left of this table listing all websites.[1]

Do not define the protocol of $wgPiwikURL
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension() If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension( 'Piwik' );, you need to use:

require_once "$IP/extensions/Piwik/Piwik.php";

Configuration parameters[edit]

Disable cookies by setting the $wgPiwikDisableCookies variable to true. For example:

$wgPiwikDisableCookies = true;

To define custom javascript tags in the Piwik javascript code, its possible to define the $wgPiwikCustomJS variable. For example if you have a single setting to insert; use the following code:

$wgPiwikCustomJS = "_paq.push(['trackGoal', '1']);";

If you have multiple variables to define; use an array. For example:

$wgPiwikCustomJS = array( 
    "_paq.push(['setCustomVariable', '1','environment','production']);",
    "_paq.push(['setCustomVariable', '1','is_user','yes']);"

If you want to change the title of your pages inside the Piwik tracker, set $wgPiwikActionName inside your LocalSettings.php file.

In case you want to include the title as, for example, "wiki/Title of the page", you can set $wgPiwikUsePageTitle to true and set $wgPiwikActionName to wiki/. The extension will print piwik_action_name = 'wiki/Title of the page';

By setting $wgPiwikIgnoreSysops to false you can enable Piwik to also count page hits done by MediaWiki users who have the "protect" user right. By default, sysop users have this right and so - by default - their page hits are not counted. Default: $wgPiwikIgnoreSysops = true.

By setting $wgPiwikIgnoreBots to false, you can enable Piwik to also count page hits done by MediaWiki users who have the bot right. By default their page hits are not counted. Default: $wgPiwikIgnoreBots = true.

When the JavaScript is deactivated, there is a fallback method using a hidden image. You can set the protocol (HTTP or HTTPS) calling this image with $wgPiwikProtocol with one of the following values: 'http', 'https', 'auto' (automatically set the protocol depending on the protocol used by the wiki).

If you have Piwik 2.7.0 or greater, you can set $wgPiwikTrackUsernames if you want to save the username of logged-in users in Piwik.

If you use a CDN to distribute the file "piwik.js", you need the version incorporating this pull request (2.4.3+) and you can set $wgPiwikJSFileURL = 'assets.example.org/piwik.js'; (do not write the protocol "http://" or "https://", it is automatically added); the parameter $wgPiwikURL must still be configured with the Piwik server collecting analytics.

Tracking with MobileFrontend[edit]

Due to a bug in Hooks/SkinAfterBottomScripts , Piwik Integration will not function when 'Mobile view' mode is used with the MobileFrontend Extension.

For those desiring to track across both views, comment or delete the Piwik Integration entries in LocalSettings.php and add to the file:

$wgUseSiteJS = true;

Then paste the Piwik tracking code generated in the Piwik dashboard into http://www.example.com/wiki/MediaWiki:Common.js. Piwik will now track users in both Desktop view and Mobile view. Take care: This workaround currently breaks the VisualEditor Extension. (2015-10-01)

Piwik configuration optimized for MediaWiki[edit]

Search parameters[edit]

By default Piwik recognize the searches on the internal search engine (the page Special:Search), because the URL parameter used by MediaWiki ("search") is in the default recognized parameters.

This can also be slightly improved by setting the two parameters:

  • "Query parameter" = "search": this will remove some false positives compared to the default value;
  • "Category parameter" = "profile": Piwik will recognize as search category the profile on top of the MediaWiki search page.

This can be either as global parameters in Administration > Websites > Settings > Tracking Internal Site Search, but preferably in the site-specific configuration in Administration > Websites > Manage > [your wiki] > Edit and uncheck "Use default Site Search parameters" and fill the paremters.

See also[edit]