Extension:Matomo

From MediaWiki.org
(Redirected from Extension:Piwik Integration)
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Matomo
Release status: stable
Implementation User activity
Description Inserts Matomo script into pages for tracking
Author(s)
  • Isb1009,
  • Youri van den Bogert,
  • DaSch,
  • Seb35
Latest version 4.0.1 (2019-02-28)
MediaWiki 1.27+
PHP 5.4+
Composer mediawiki/matomo
License GNU General Public License 2.0 or later
Download
README
  • $wgMatomoIDSite
  • $wgMatomoURL
  • $wgMatomoIgnoreSysops
  • $wgMatomoIgnoreBots
  • $wgMatomoCustomJS
  • $wgMatomoUsePageTitle
  • $wgMatomoActionName
  • $wgMatomoDisableCookies
  • $wgMatomoProtocol
  • $wgMatomoTrackUsernames
  • $wgMatomoJSFileURL
Translate the Matomo extension if it is available at translatewiki.net
Check usage and version matrix.

The Matomo extension (formerly "Piwik Integration") 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.

This extension was renamed in February 2019 from "Piwik Integration" to "Matomo", given the underlying software was renamed in January 2018 (more explanations).

Requirements[edit]

  • MediaWiki 1.27+ (tested up to MediaWiki 1.32)
  • Matomo 0.4+ with the site configured

Installation instructions[edit]

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

Make sure to set $wgMatomoIDSite to the ID of your site in Matomo. For the first site, this ID will usually be "1". In Matomo, 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 $wgMatomoURL
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Upgrade[edit]

This extension was renamed from "Piwik Integration" to "Matomo" from version 4.0 :

  • if you installed it with Composer, rename the package "mediawiki/piwik-integration" to "mediawiki/composer";
  • if you installed it as a classical MediaWiki extension, rename the directory "Piwik" or "Piwik Integration" to "Matomo".

In both cases, now you need to explicitely activate the extension with wfLoadExtension( 'Matomo' );

Matomo settings not working yet[edit]

As reported in [1] at least one of the following does not work yet:

   $wgMatomoURL = "...";
   $wgMatomoIDSite = "...";
   $wgMatomoIgnoreSysops = false;
   $wgMatomoTrackUsernames = true;

When those are used sites are not tracked. Change Matomo to Piwik (e.g. wgMatomoURL -> wgPiwikURL) to start getting results. This is during an upgrade from the most recent piwik extension to the matomo one via composer, not sure if required in other scenarios.

Configuration parameters[edit]

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

$wgMatomoDisableCookies = true;

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

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

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

$wgMatomoCustomJS = 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 Matomo tracker, set $wgMatomoActionName inside your LocalSettings.php file.

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

By setting $wgMatomoIgnoreSysops to false you can enable Matomo 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: $wgMatomoIgnoreSysops = true.

By setting $wgMatomoIgnoreBots to false, you can enable Matomo to also count page hits done by MediaWiki users who have the bot right. By default their page hits are not counted. Default: $wgMatomoIgnoreBots = 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 $wgMatomoProtocol with one of the following values: 'http', 'https', 'auto' (automatically set the protocol depending on the protocol used by the wiki).

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

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 $wgMatomoJSFileURL = 'assets.example.org/piwik.js'; (do not write the protocol "http://" or "https://", it is automatically added); the parameter $wgMatomoURL must still be configured with the Matomo server collecting analytics.

Tracking with MobileFrontend[edit]

Due to a bug in Hooks/SkinAfterBottomScripts , Matomo 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 Matomo entries in LocalSettings.php and add to the file:

$wgUseSiteJS = true;

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

Matomo configuration optimized for MediaWiki[edit]

Search parameters[edit]

By default Matomo 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": Matomo 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]

References[edit]