Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track 404 errors #46

Open
samwilson opened this issue Jan 5, 2024 · 5 comments
Open

Track 404 errors #46

samwilson opened this issue Jan 5, 2024 · 5 comments

Comments

@samwilson
Copy link
Contributor

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
Copy link
Contributor Author

There's some more information here, and an alternative way to track 404s: matomo-org/matomo#6580

samwilson added a commit to samwilson/matomo-mediawiki-extension that referenced this issue Jan 10, 2024
Add code to set the page title to include information about the
URL and referrer for pages that do not exist. Based on
recommendations at https://matomo.org/faq/how-to/faq_60/

Bug: DaSchTour#46
samwilson added a commit to samwilson/matomo-mediawiki-extension that referenced this issue Jan 10, 2024
Add code to set the page title to include information about the
URL and referrer for pages that do not exist. Based on
recommendations at https://matomo.org/faq/how-to/faq_60/

Also fix some minor phpdoc syntax.

Bug: DaSchTour#46
@Seb35
Copy link
Collaborator

Seb35 commented Mar 22, 2024

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
Copy link
Collaborator

Seb35 commented Mar 22, 2024

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.

@samwilson
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants