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

Trouble tracking 404 pages #11882

Closed
Holiez opened this issue Jul 19, 2017 · 2 comments
Closed

Trouble tracking 404 pages #11882

Holiez opened this issue Jul 19, 2017 · 2 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@Holiez
Copy link

Holiez commented Jul 19, 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
Copy link
Contributor

RMastop commented Jul 19, 2017

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.
Cheers,
Richard

@Holiez
Copy link
Author

Holiez commented Jul 20, 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.

@Holiez Holiez closed this as completed Jul 20, 2017
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Sep 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

3 participants