@Holiez opened this Issue on July 19th 2017

I'm trying to track 404 pages in Piwik for my website. First thing I've tried is this How To from the official site:

<?php if( is_404() ) {  ?> 
 _paq.push(['setDocumentTitle',  '404/URL = ' +  encodeURIComponent(document.location.pathname+document.location.search) + '/From = ' + encodeURIComponent(document.referrer)]);
<?php } ?>

That didn't work: there was no '404' entry on the Actions>Pages list. I know for sure there were 404 pages because I'm sending myself an e-mail everytime a visitor lands on a 404. I've checked that code snippet was correctly added to my page, and also made sure it was placed before the trackPageView bit.

So I tried another method: tracking a Custom Variable every time a 404 was loaded.

<?php if( is_404() ) { ?>
_paq.push(['setCustomVariable', 1, '404 Error', '<?php echo getUrl(); ?>', 'page']); 
 <?php } ?>

getUrl is a custom function that returns the current URL. The function works fine, when looking at the source code the correct URL is there. This works a bit better, as I'm getting data for this Custom Variable, but it's not without flaws: for some reason, some pages are not tracked (again, comparing with the alert e-mails I'm receiving). Also, I've created a new Segment based on this variable and when viewing the reports for this segment there is no data at all for the Actions>Pages report.

@RMastop commented on July 19th 2017 Contributor

The _paq.push part is correct, are you sure the function is_404 is handled correctly?
If so, are you adding the setDocumentTitle before the TrackPageView, it should.

@Holiez commented on July 20th 2017

The function and the tracking code is 100% correct. I think I've found the issue though, which isn't actually an issue: I've checked my server logs and all the 404 came from search index robots, and it would make sense that Piwik wouldn't track those. The Custom Variables that got tracked were only my visits (despite having the Do Not Track cookie, mind you). Case closed.

This Issue was closed on July 20th 2017
Powered by GitHub Issue Mirror