Google Analytics has always been more than a hit counter and demographic tool -- you could build a career out of being a Google Analytics analyst. You can measure ad campaign effectiveness, track how far into a desired page flow (think advertisement to cart to checkout) users get, and set browser and locale support based your user's information.
But that's all stuff for the suits, not us devs. What us nerds can use Google Analytics for, however, is error tracking via custom events. Here's a quick look at how I've implemented error checking in analytics:
Now when you go into Google Analytics, you can view the custom event information along with other site stats. Of course you'll tell the marketing people those aren't really error, they're features, but that's another story. Consider using Google Analytics for to track site errors -- you can thank me later.
It’s easy to track js errors with google analytics, but there are problems with this way of tracking, too.
The main problem is grouping: you will get millions of events from different users, browsers (every browser reports errors with different message), and languages (because IE reports in local languages).
You will not get much useful data like stacktraces or user actions proior to the error from Google Analyitcs.
At Qbaka (sorry for marketing, but everyone is free to compare our tool to others) we have smart error groping, track user actions to show how to reproduce error, filter out the noise and show you how many users were affected (and show exact users), support source maps and much more. It’s free for small projects, may be a valuable alternative to Google Analytics tracking.
We’ve been doing this as well at work, but there’s one thing we found you’ll want to change here.
_trackEventhas a fifth parameter, namely “nonInteractive”, as you can see: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
It’d be best to pass
trueas the fifth param, otherwise any errors being tracked this way will affect the bounce rate metrics on your site; as far as I know, an “interactive” event tracked after a pageview makes GA consider it a non-bounce. If a JS error occurs right after pageload, and the user then closes the page, it won’t register as a bounce.
Other than that, definitely a useful snippet if you don’t have the means to splurge on new relic for client-side!