Question

I'd like to have better error page reporting in Google Analytics. Currently, if someone does something on my site which causes a problem, they see an error page instead of the content they expected. The URL remains the same. So if they went to www.example.com/view_my_profile and there was a problem with their profile, they would see an error page at that URL.

What I'd like to do is send Google Analytics a virtual pageview of something like www.example.com/error/view_my_profile/ (maybe an event captures the extra parameters better?). That's easy enough. But I want this virtal pageview to happen instead of the /view_my_profile real pageview. Because that real page wasn't actually viewed and it would be registering an extra pageview on my site.

Is this as simple as leaving out the _trackPageView call in the google analytics snippet below or am I asking for trouble?

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-${gaAccount}-1']);
  _gaq.push(['_trackPageview']);
Was it helpful?

Solution

Way over-complicating things..just use _trackPageView like normal but pass a value (virtual URL) to it for the URL you want it to be. It will count as a page view for the URL you pass it instead of the current URL.

OTHER TIPS

You can do this without complication. As long as you load ga.js, instantiate var gaq, and set the account, you can make any calls you want, including _trackPageview with only a virtual pageview value.

You don't even need to call the organic _trackPageview -- you could just do event tracking. In fact, you might want to consider doing an organic pageview, coupled with an Event Tracking that passes some detailed error tracking info to you. Because there can be up to 4 parameters, you can log more and better structured data.

So, on your 404 page, you could call something like:

_gaq.push(['_trackEvent', '404 Error', location.pathname, document.referrer, time_stamp_value]);

(where you've previously defined time_stamp_value as a non-float Number.)

Something that simple will allow you to create hierarchies for your errors, count them more easily, and even do things like the referring page and a timestamp value, without cluttering your pageview information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top