Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

62 lines (46 sloc) 1.87 KB


A simple library for detecting javascript runtime errors and reporting them via google analytics.


This library assumes that you are using Google Analytics for tracking page views and other events on your web application. For more information on how to setup google analytics, refer to documentation at

To setup google analytics tracking for unhandled errors,

  • Include the js-watson.js file in your page(s)
  • Set window.onerror = JsWatson.trackUnhandledError
  • That's it.

Now, any unhandled errors on your web pages should get reported to your google analytics account as a page view, with the script file name and the line number on which the error occured as part of the page view URL.

Over time, you can see the trends, which browsers are getting the errors, etc. There is much more to how you can analyze where errors are occuring, using the full power of google analytics.


First, ensure you're google analytics setup is otherwise properly configured and is already reporting page views and other events to google.


<script src="/javascripts/js-watson.js" type="text/javascript"></script>

<!-- google analytics initialization --> 
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


  window.onload=function() {
    window.onerror = JsWatson.trackUnhandledError;
    // other stuff ...
Jump to Line
Something went wrong with that request. Please try again.