Skip to content

Instantly share code, notes, and snippets.

@fortis
Last active June 28, 2016 18:12
Show Gist options
  • Save fortis/8ba85fb951ca207ad5a918e217785133 to your computer and use it in GitHub Desktop.
Save fortis/8ba85fb951ca207ad5a918e217785133 to your computer and use it in GitHub Desktop.
<script>
window.addEventListener('error', function (e) {
ga('send', 'exception', {
exDescription: 'JavaScript Error ' + e.message + ' ' + e.filename + ': ' + e.lineno
});
});
jQuery(document).ajaxError(function (e, request, settings) {
ga('send', 'exception', {
exDescription: 'Ajax Error ' + settings.url + ' ' + e.result
});
});
// V2
// Track basic JavaScript errors
window.addEventListener('error', function(e) {
_gaq.push([
'_trackEvent',
'JavaScript Error',
e.message,
e.filename + ': ' + e.lineno,
true
]);
});
// Track AJAX errors (jQuery API)
$(document).ajaxError(function(e, request, settings) {
_gaq.push([
'_trackEvent',
'Ajax error',
settings.url,
e.result,
true
]);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment