How to analyze 404-hits on the site?

Hi, maybe I am wrong here.

We use Joomla and have piwik installed (on the server runs mod_removeip, btw).

Now, we encounter 24.000 hits on the custom 404-page.

Is it possible to find out, which URLs have been entered by the users, leading to the 404-error?

Can piwik do this? how? Where to se that information?

Best regards,
Ricardo Cristof

You should be able to add the JavaScript tracker on a custom 404 page, and then you should get the offending page from the referrer. Depends a little on the web server platform and setup.

yes if you create a new website in Piwik specifically for this page, and add the piwik code to this page, you will then see all referers leading to the 404 page in your reports for this website.

There is a better solution, check out How to track 404 pages in Piwik?

Hello all.
I am sorry but i just don’t manage to track my 404 page.

I have entered the default Piwik Tracking-Code.
And now it says i should edit the code with this special codefeed - but how?

Do i have to replace some of the original code? Do i have to enter the code at a special place? (I guess so, since i didn’t get it to work.)

Can anyone help me with further instructions?

Thank you, Phill

SOLVED!
It belongst between:

var piwikTracker = Piwik.getTracker(pkBaseURL + “piwik.php”, 1);
AND
piwikTracker.trackPageView();

So it looks like:

var piwikTracker = Piwik.getTracker(pkBaseURL + “piwik.php”, 1);
piwikTracker.setDocumentTitle('404/URL = '+encodeURIComponent(document.location.pathname+document.location.search) + '/From = ’ + encodeURIComponent(document.referrer));
piwikTracker.trackPageView();

Enjoy!

Thanks for the feedback. I have updated the FAQ answer to make it easier to understand.

Are the encodeURIComponent() calls necessary? (It seems to me this would result in double-encoding since piwik.js also calls encodeURIComponent().)

It was put there to encore the “/” otherwise it would create too many categories in the Page title report. Technically we should only replace the “/” in the strings with the encoded /.

the new code should read:

piwikTracker.setDocumentTitle('404/URL = '+String(document.location.pathname+document.location.search).replace(/\//g,"%2f") + '/From = ' + String(document.referrer).replace(/\//g,"%2f"));

I’ll check it on the piwik.org 404 page and will update faq if working as expected. thanks for the review

Hi

I tried adding this line in my error 404 page

piwikTracker.setDocumentTitle('404/URL = '+String(document.location.pathname+document.location.search).replace(///g,"%2f"winking smiley + '/From = ’ + String(document.referrer).replace(///g,"%2f"winking smiley);

and entered some invalid url’s to test it. No pages were tracked using this code. So I changed it to

piwikTracker.setDocumentTitle('404/URL = '+encodeURIComponent(document.location.pathname+document.location.search) + '/From = ’ + encodeURIComponent(document.referrer));

and tried the same tests and it worked. The page titles come up as the url entered with 404/URL= …

When using this, under Actions->Pages , the file listed is the invalid url rather than the filename of the error 404 page. Is this the way its supposed to happen?

Thanks,
Rob

Maybe use setCustomUrl to prefix the URLs, eg “404/”

The right code is in the FAQ: How to - Analytics Platform - Matomo (forum seems to be messing up with code and adding smileys)

ha!

in the case that the piwik tracking code exists in a Joomla site template (which is the right place to add the piwik code), if I add this code again (with the addition for the 404) in the 404 page article, then in the source code of the new 404 page, I get both piwik codes, which I don’t think is right. One gets generated from the Joomla template and one from the article.

In fact (without adding the code as described here: How to - Analytics Platform - Matomo ), if I go to Actions > Page Titles, I do already have 404 page hits recorded by piwik, but the number I see (about 2, 3 hits) is not real.

I also tried creating a goal for pages that include the word “404”, and it records nothing.

Any ideas ?
thanks

To avoid generating the code twice you will have to implement a variable check in the FOOTER file, for example

404.tpl: contains piwik code and sets a “template variable” (whatever template language joomla or wordpress or etc. uses)
piwikCodeAlreadyDisplayed=true

footer.tpl: display the js code only if piwikCodeAlreadyDisplayed==false (or not defined)

thanks for the reply matt, will check it out as soon as possible and ask for your help if I cannot make it :slight_smile:
thanks dude

Hi guys,

I can’t get this to work. I got the following the my htaccess on my webserver:


ErrorDocument 404 http://www.myurl.com/404.html

My visitor-log now only shows and lost the entered wrong url.


404/URL = /404.html/From =

Any ideas how to solve this? I used the code of the FAQ.

Kind regards
Marucs