Last active
June 28, 2016 18:12
-
-
Save fortis/8ba85fb951ca207ad5a918e217785133 to your computer and use it in GitHub Desktop.
JavaScript / AJAX Error Monitoring via Google Analytics https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions#exception_fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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