Skip to content

Instantly share code, notes, and snippets.

@jolos
Created November 3, 2012 14:18
Show Gist options
  • Select an option

  • Save jolos/4007504 to your computer and use it in GitHub Desktop.

Select an option

Save jolos/4007504 to your computer and use it in GitHub Desktop.
Client side error logging with Google analytics

With client side code ( aka javascript ) becoming a crucial part of modern websites/webapplications, it's also becoming more difficult to know what is happening when the code is actually being executed. Code failing on a server is relatively easy to spot, this is not the case with javascript. Hence, if you're building a serious client side application robust logging is one of the first things you should set up. ( In fact this also holds for backend systems ).

For my own website I'm keeping it simple and I'm leveraging google analytics to log possible errors. As you see this is not rocket science but it's a good way to spot possible errors.

window.error_log = function(type, msg) {
_gaq.push(['_trackEvent', 'error', type, msg]);
}
try {
// some code that might throw an error.
} catch(err){
// <type> can be anything here.
error_log('<type>', err.get_message());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment