Skip to content

Instantly share code, notes, and snippets.

@BBB
Created June 8, 2012 13:32
Show Gist options
  • Save BBB/2895634 to your computer and use it in GitHub Desktop.
Save BBB/2895634 to your computer and use it in GitHub Desktop.
GA.js track errors
// For hackers:
window.onerror = function(m, f, l){
var err = JSON.encode({ message:m, file:f, line:l })
(new Image).src = '/errors?e='+err
}
// For Google Analytics users:
window.onerror = function(m, f, l){
var err = [f, l, m].join(' : ')
_gaq.push(['_trackEvent', 'Errors', 'App', err, null, true])
}
// Analytics will allow you to filter by OS, browser, and all the other environment data it already captures. And nice graphs as a bonus :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment