Search by

octfx / plausible

Octfx

Integrates plausible analytics

Package info

github.com/octfx/mediawiki-extension-Plausible

Homepage

Type:mediawiki-extension

pkg:composer/octfx/plausible

Statistics

Installs: 1 174

Dependents: 0

Suggesters: 0

Stars: 10

Open Issues: 1

1.4.0 2023-12-14 08:29 UTC

This package is auto-updated.

Last update: 2026-10-29 16:13:24 UTC


README

Plausible Analytics is a simple, lightweight (< 1 KB), open-source and privacy-friendly alternative to Google Analytics. It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR.

See https://github.com/plausible/analytics

Installation

  • Download, extract and place the file(s) in a directory called Plausible in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'Plausible' );  
$wgPlausibleDomain = "https://plausible.io";  
$wgPlausibleDomainKey = "mywiki.example.com"; // change to your site address
$wgPlausibleApikey = ''; // Only necessary when using Extension:PageViewInfo
  • Configure as required.
  • Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

Key Description Example Default
$wgPlausibleTrackerMode Tracker format: legacy or site-specific. See Tracker modes. 'site-specific' 'legacy'
$wgPlausibleScriptUrl Site-specific script URL from the Plausible installation snippet. Required in site-specific mode. https://plausible.io/js/pa-example.js null
$wgPlausibleDomain Plausible domain. Required for legacy tracking and server-side tracking. https://plausible.io null
$wgPlausibleDomainKey Domain key set in Plausible. Required for legacy tracking and server-side tracking. plausible.io null
$wgPlausibleApiKey Auth Bearer key for integration with Extension:PageViewInfo
$wgPlausibleHonorDNT Honor the Do Not Track header for browser-side tracking. This does not prevent server-side events. false true
$wgPlausibleTrackOutboundLinks Enable Tracking of outbound link clicks. true false
$wgPlausibleTrackFileDownloads Enable Tracking of link clicks that lead to files, sending a File Download event. See the official docs. true false
$wgPlausibleTrackFileDownloadExtensions File extensions to track. Legacy mode adds them to the defaults; site-specific mode replaces the defaults when the list is not empty. ['js', 'py'] []
$wgPlausibleTrackLoggedIn Enable Tracking for logged in users. true false
$wgPlausibleEnableTaggedEvents Enable tagged events in legacy mode. The site-specific tracker enables tagged events regardless of this setting. true false
$wgPlausibleIgnoredTitles URL path patterns excluded from browser pageviews in both modes. Custom events are not excluded by path. ['/Page1', '/Special:*'] []
$wgPlausibleEnableOptOutTag Enables the <plausible-opt-out /> tag for browser-side tracking. Opting out does not prevent server-side events. false true

Tracker modes

Legacy mode is the default. It uses Plausible's legacy script variants and supports self-hosted Plausible v2.0.0.

Site-specific mode is a work in progress. Do not use it in production: browser controls have not been fully verified. It requires a Plausible deployment that provides a site-specific tracker. Plausible Community Edition introduced this tracker in v3.1.0. Live Cloud and self-hosted compatibility has not yet been verified.

To opt in, copy the script URL from your site's Plausible installation snippet:

$wgPlausibleTrackerMode = 'site-specific';
$wgPlausibleScriptUrl = 'https://plausible.io/js/pa-example.js'; // Replace with your site's script URL.

The extension's outbound-link and file-download settings override the Plausible site settings. With downloads enabled, an empty extension list uses Plausible's defaults. A non-empty list replaces them in site-specific mode. Legacy mode adds the listed extensions to the defaults.

The site-specific tracker enables tagged events independently of $wgPlausibleEnableTaggedEvents. Legacy mode uses that setting to enable or disable tagged events.

$wgPlausibleIgnoredTitles matches browser URL paths, not MediaWiki title text. It uses Plausible's legacy wildcard and regular-expression matching rules in both modes. For examples, see Plausible's exclusion documentation. Exclusions do not suppress custom events or server-side events.

If you use a Content Security Policy, allow the tracker script origin in script-src and the event endpoint origin in connect-src. These origins may differ when using a proxy.

Included tracking scripts

The following tracking modules can be activated by setting the provided configuration key in LocalSettings.php to true.

Key Description Event Name
$wgPlausibleTrack404 Sends a 404 event for unknown titles. 404
$wgPlausibleTrackSearchInput Send inputs to #searchInput to plausible as a custom event named Search: Input. Search: Input
$wgPlausibleTrackEditButtonClicks Track clicks to #ca-edit a as a custom event named Edit Button: Click. Edit Button: Click
$wgPlausibleTrackNavplateClicks Track clicks to links inside .navplate elements. Navplate: Click
$wgPlausibleTrackInfoboxClicks Track clicks to links inside .mw-capiunto-infobox and .infobox elements. Infobox: Click
$wgPlausibleTrackCitizenSearchLinks Only for Skin:Citizen. Track clicks to search result links found in #typeahead-suggestions. Event is named Citizen: Search Link Click. Citizen: Search Link Click
$wgPlausibleTrackCitizenMenuLinks Only for Skin:Citizen. Track clicks to links in the sidebar menu. Event is named Citizen: Menu Link Click. Citizen: Menu Link Click

Server Side Tracking

Some events can be sent server-side without relying on the Plausible client script. The DNT setting and browser opt-out do not prevent these events. The opt-out uses browser local storage, which the server cannot read.

The following custom events can be activated:

# Default Configuration
$wgPlausibleServerSideTracking = [
    // Event Name: pageview
    'pageview' => false,
    // Event Name: 404 
    'page404' => false,
    // Event Name: Page: Edit 
    'pageedit' => true, // Page has been successfully edited
    // Event Name: Page: Delete
    'pagedelete' => true, // Page has been deleted
    // Event Name: Page: Undelete
    'pageundelete' => true, // Page has been undeleted
    // Event Name: Page: Move
    'pagemove' => true, // Page was moved
    // Event Name: User: Register
    'userregister' => false, // A new user registered
    // Event Name: User: Login
    'userlogin' => false, // A user logged in
    // Event Name: User: Logout
    'userlogout' =>  false, // A user logged out
    // Event Name: File: Upload
    'fileupload' => true, // A file was uploaded
    // Event Name: File: Delete
    'filedelete' => true, // A file was deleted
    // Event Name: File: Undelete
    'fileundelete' => true, // A file was undeleted
    // Event Name: Search: Not found
    'searchnotfound' => true, // A searched term was not found / has no title on the wiki
    // Event Name: Search: Found
    'searchfound' => true, // A searched term was found / has a corresponding title on the wiki
];

Event / Goal Names

This extension chooses the following convention for naming events / goals: Subject: Event/Action.

Tracking Custom Events

https://github.com/plausible/docs/blob/master/docs/custom-event-goals.md

If you want to track custom event goals like button clicks or form completions, you have to trigger these custom events from your website using JavaScript.

Scripts need to be placed in MediaWiki:<Your Skin>.js e.g. MediaWiki:Citizen.js.

Example: Tracking edit button clicks on Skin:Citizen.

if (typeof window.plausible === 'undefined') {
    return;
}

document.querySelector('#ca-edit a').addEventListener('click', function (event) {
    plausible('Edit Button: Click');
});

Via css classes

With setting $wgPlausibleEnableTaggedEvents = true; click to elements can be tracked by setting css classes. From the official docs:

You can also add class names directly in HTML If you can edit the raw HTML code of the element you want to track, you can also add the classes directly in HTML. For example:

<!-- before -->
<button>Click Me</button>
<!-- after -->
<button class="plausible-event-name=Button+Click">Click Me</button>

Or if your element already has a class attribute, just separate the new ones with a space:

<!-- before -->
<button class="some-existing-class">Click Me</button>

<!-- after -->
<button class="some-existing-class plausible-event-name=Button+Click">Click Me</button>

When you send custom events to Plausible, they won't show up in your dashboard automatically. You'll have to configure the goal for the conversion numbers to show up.

Ignoring Pages

https://github.com/plausible/docs/blob/master/docs/excluding-pages.md#common-use-cases-and-examples

By default, Plausible Analytics tracks every page you install the snippet on. If you don't want Plausible to track specific pages, do not include the snippet on those pages.

Common use cases and examples

$wgPlausibleIgnoredTitles input Prevents tracking on pages with a URL path of:
/blog4 /blog4 and exactly /blog4 with nothing before or after it, so not /blog45 nor /blog4/new nor /blog
/rule/* /rule/<anything>, with <anything> being any set of characters (length >=0), but not a forward slash - for example, both /rule/1 as well as /rule/general-rule-14, but not /rule/4/details nor /rules
/how-to-* /how-to-<anything> - for example, /how-to-play or /how-to-succeed, but not how-to-/blog
/*/admin /<anything>/admin - for example, /sites/admin, but not /sites/admin/page-2 nor /sites/2/admin nor /admin
/*/priv/* /<anything>/priv/<anything> - for example, /admin/priv/sites, but not /priv nor /priv/page nor /admin/priv
/rule/*/* /rule/<anything>/<anything> - for example, /rule/4/new/ or /rule/10/edit, but not /rule nor /rule/10/new/save
/wp/** /wp<anything, even slashes> - for example, /wp/assets/subdirectory/another/image.png or /wp/admin, and everything in between, but not /page/wp

Lua Integration

With Extension:PageViewInfo active, plausible exposes the following functions:

  1. mw.ext.plausible.topPages() Returns the top pages and the views for the last day. The table is ordered by the number of page views, and can be iterated by using ipairs.
    Example:
local result = mw.ext.plausible.topPages()
> {
  {
    page = "Foo",
    views = 100
  },
  {
    page = "Bar",
    views = 80
  },
  { [...] }
}

Alternatively this function can be called with the number of days to calculate the views over, e.g. mw.ext.plausible.topPages( 30 ).
This is expensive as no caching is employed.

  1. mw.ext.plausible.pageData( titles, days ) Returns the page views for the given titles over the last N days.
    Example:
local result = mw.ext.plausible.pageData( { "Foo", "Bar" }, 5 )
> {
  ["Foo"] = {
    ["2023-08-04"] = 10,
    ["2023-08-05"] = 1,
    ["2023-08-06"] = 4,
    ["2023-08-07"] = 7,
    ["2023-08-08"] = 1,
    ["2023-08-09"] = 4,
  },
  ["Bar"] = {
    ["2023-08-04"] = 100,
    ["2023-08-05"] = 14,
    ["2023-08-06"] = 54,
    ["2023-08-07"] = 7,
    ["2023-08-08"] = 31,
    ["2023-08-09"] = 1,
  },
}
  1. mw.ext.plausible.siteData( days ) Returns the site views for the given last N days.
    Example:
local result = mw.ext.plausible.siteData( 5 )
> {
  ["2023-08-04"] = 10,
  ["2023-08-05"] = 1,
  ["2023-08-06"] = 4,
  ["2023-08-07"] = 7,
  ["2023-08-08"] = 1,
  ["2023-08-09"] = 4,
}