用Google Analytics跟踪JavaScript Errors (译)

通过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.

来自: http://davidwalsh.name/track-errors-google-analytics

转载于:https://www.cnblogs.com/JoannaQ/p/3669818.html

猜你喜欢

转载自blog.csdn.net/weixin_34404393/article/details/94153436