Extension:Analytics

Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:GPL licensed extensions
MediaWiki extensions manual
Analytics
Release status: stableCategory:Stable extensions
Implementation Special page Category:Special page extensions
Description Traffic and edit analytics for the entire wiki, as well as specific categories and pages
Author(s) Sophivorustalk
Latest version 1.2
MediaWiki 1.39+Category:Extensions with manual MediaWiki version
PHP 8+
Database changes Yes
License GNU General Public License 3.0 or later
Download Category:Extensions in Wikimedia version control
Example Appropedia
  • $wgAnalyticsCountPageViews
Quarterly downloads 18 (Ranked 80th)
Translate the Analytics extension if it is available at translatewiki.net
Category:All extensions

The Analytics extension gives access to traffic and edit analytics for the entire wiki, as well as for specific categories and pages, in three ways:

  • A special page called Special:Analytics where you can explore freely through a simple UI (example)
  • A Lua library called mw.ext.analytics that exposes the data to Lua modules and templates (example)
  • A REST API endpoint called /analytics that exposes the data to other software and scripts (example)

Installation

  • Download and move the extracted Analytics folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Analytics
  • Only when installing from Git, run Composer to install PHP dependencies, by issuing composer install --no-dev in the extension directory. (See T173141 for potential complications.)Category:Extensions requiring Composer with git
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Analytics' );
    
  • Run the update script which will automatically create the necessary database tables that this extension needs.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Tracking page views

When installed, this extension will create a database table called analytics_pageviews and will start tracking the daily pageviews to each page. However, if you're installing this extension some time after your wiki started, then the pageviews table will lack historical data. If you've been using Google Analytics (GA4), you can use the maintenance script bundled with this extension to populate the pageviews table with the historical data, like so:

php /path/to/w/maintenance/run.php /path/to/w/extensions/Analytics/maintenance/populatePageViewsFromGA4.php --credentials /path/to/google-cloud-credentials.json --property 123456789

Furthermore, if your wiki is using a proxy (like Cloudflare), then many or even most of your pageviews will not reach your server, which means this extension won't be able to track them. To work around this, if you're using GA4, run the maintenance script with --days 1 using a daily cronjob to keep your pageviews table up to date. If you do, you may also want to set $wgAnalyticsCountPageViews = false; in your LocalSettings.php to disable the default tracking of pageviews.

See also

Category:Web Analytics extensions Category:Statistics extensions
Category:All extensions Category:Extensions in Wikimedia version control Category:Extensions requiring Composer with git Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:LoadExtensionSchemaUpdates extensions Category:PageViewUpdates extensions Category:ScribuntoExternalLibraries extensions Category:Special page extensions Category:Stable extensions Category:Statistics extensions Category:Web Analytics extensions