matomo-mediawiki-extension icon indicating copy to clipboard operation
matomo-mediawiki-extension copied to clipboard

Track 404 errors

Open samwilson opened this issue 1 year ago • 5 comments

The Matomo docs suggest tracking 404 errors like this:

Setup a custom 404 page: you can easily do this if you use a CMS (for example, in wordpress, all 404 pages are loading a custom 404 template). If you don’t use a Content Management System, you can usually specify a 404 custom page in your webserver configuration file. Add the Matomo tracking code in this custom 404 page. In the Javascript tracking code, add the following: _paq.push(['setDocumentTitle', '404/URL = ' + encodeURIComponent(document.location.pathname+document.location.search) + '/From = ' + encodeURIComponent(document.referrer)]);

Is this something that this extension could handle?

samwilson avatar Jan 05 '24 06:01 samwilson

There's some more information here, and an alternative way to track 404s: https://github.com/matomo-org/matomo/issues/6580

samwilson avatar Jan 10 '24 10:01 samwilson

Indeed, it would be something useful to understand what the visitors do not find – MediaWiki has already the special pages Wanted* (WantedPages, WantedCategories, …) but it’s more from the point of view of the editors (what pages should we create?) instead of the visitors (what pages do we want to see? including pages not anticipated by the editors).

Given Matomo has no official method to support that (but it could appear in the future), perhaps the best way for now is to use one of the method described in the links in the parameter $wgMatomoCustomJS (which is written before the call to trackPageView):

And experiment what is the more convenient. When a method will be stable, it could be documented on the mediawiki.org page.

Seb35 avatar Mar 22 '24 10:03 Seb35

And experiment what is the more convenient. When a method will be stable, it could be documented on the mediawiki.org page.

Ah, I realise some support from this extension is necessary to conditionnally include this JS snippet only on the 404 page, or perhaps more generally add a JS variable with the HTTP status code to be retrieved with mw.config.get( 'wgHTTPStatus' );

EDIT: and I see your PR #47.

Seb35 avatar Mar 22 '24 11:03 Seb35

Yeah it's odd that Matomo doesn't have a better way to track them, but changing the title seems to work okay. The adding of the slashes means that it displays it grouped in the same way it does other directories.

Does that PR look ok?

samwilson avatar Mar 23 '24 01:03 samwilson

@Seb35 Gentle reminder about this. Let me know if you want me to update the PR in any way.

samwilson avatar Jun 10 '24 06:06 samwilson