通过custom events来实施
// 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 ]); });
Now when you go into Google Analytics, you can view the custom event information along with other site stats. Of course you'll tell the marketing people those aren't really error, they're features, but that's another story. Consider using Google Analytics for to track site errors -- you can thank me later.