Θ ThetaBoard

Managing Projects is Hard

ThetaBoard is Easy

Simple, powerful, real-time project management app for teams

ThetaBoard is currently in beta. Sign up for a FREE account today.

ThetaBoard Screenshot

Client-Side Error Logging With Google Analytics

Apr 5th, 2012 / Javascript Exception Handling Google Analytics

There was a post on Hacker News yesterday encouraging developers to log client-side errors. Doing so will allow you to identify errors your visitors see but just aren't telling you about. There are several options that will allow you to track these exception.

Roll your own solution

If you want to get your hands dirty, you can write your own logging system. When an error occurs on the client side, make an jquery.ajax call to your server and log the information in a database, text file, redis etc. If you have a buggy application or some disrespectful 3rd-party libraries, this might put a heavy load on your servers. One recommendation was to aggregate and filter the errors at the client using localStorage and then send them in bulk.

If you want full, fine-grained control, this may be your best option.

Logging as a Service

There are several SaaS offerings that will handle this for you. A few worth looking into include:

Most of these services offer a free tier that will get you started but be prepared to pay at least $10 to $15 bucks a month for your small web app.

Google Analytics: Free and (almost) Installed Already

A third idea that came out of the thread (thanks @DavidPaquet at Okam) was to use Google Analytics to log these exceptions. It may not offer the power of the SaaS offerings but the price is right (free) and setup is a cinch. You simply modify your "window.onerror" method to register an "Event" in Google Analytics:

In a few hours, you'll start seeing your errors show up in Google Analytics. You'll find your Events data in Content > Events. Experimenting with Metrics and Dimensions reveal some pretty useful information:

It's a pretty simple solution to a tricky problem:

  • You probably already have Google Analytics installed. You literally just have to add 3 lines of code.
  • Let Google shoulder the server load. By relying on Google Analytics for this logging, you free up your servers for more important tasks.
  • Track the impact of client-side errors on other business metrics. With the reporting in Google Analytics you can see how these errors are affecting bounce rate, conversion and sales.

Ok, so it's not perfect

There are definite drawbacks to this solution. It it will take a few hours before you see the data in Google Analyics so it's not a real-time solution.

Also, window.onerror sucks--it doesn't give you a ton of information. If you minify your javascript, you won't learn much from the file and line number information either.

I'm going to experiment with wrapping my javascript in a Try/Catch block (pros and cons to this) and see if I can pass more information with the GA Event.

TL;DR

Given the cost associated with the SaaS offerings, the headaches with the roll-you-own solution, and the free and powerful reporting that Google Analyics provides, you may want to use Google Analytics to log your client-side errors.

Discuss on Hacker News

blog comments powered by Disqus