Add Privatus Analytics to MediaWiki
Add cookieless analytics to a MediaWiki site by loading the tracker from MediaWiki:Common.js for every reader, with no cookies and no banner.
MediaWiki loads the page MediaWiki:Common.js for all users on all skins.
You need the rights to edit site JavaScript on your wiki.
- Open
MediaWiki:Common.json your wiki and edit it. - Add this code:
js
var s = document.createElement('script')
s.defer = true
s.src = 'https://privatusstats.com/js/pa.js'
s.setAttribute('data-site', 'pa_YOURSITEID')
s.setAttribute('data-modules', 'engage,auto,vitals,clicks,ask')
document.head.appendChild(s)
- Save, then reload a page and look for
/js/pa.jsin the network tab.
The tracker reads its settings from the script element, so set each attribute before you add the element to the page.
Mobile site#
The mobile site from MobileFrontend ignores Common.js. Put the
same code in MediaWiki:Mobile.js to count mobile readers. A skin only
script such as MediaWiki:Vector.js affects just that skin.
If your wiki sets a Content Security Policy, allow the tracker host in its
script-src directive.