使用Google Analytics(分析)跟踪JavaScript错误

Google Analytics has always been more than a hit counter and demographic tool -- you could build a career out of being a Google Analytics analyst.  You can measure ad campaign effectiveness, track how far into a desired page flow (think advertisement to cart to checkout) users get, and set browser and locale support based your user's information.

一直以来,Google Analytics(分析)都不只是计数器和人口统计工具,您可以成为一名Google Analytics(分析)分析师,从而发展事业。 您可以衡量广告活动的有效性,跟踪用户获得所需页面流(想想将广告投放到购物车以结帐)的程度,并根据用户的信息设置浏览器和区域设置支持。

But that's all stuff for the suits, not us devs.  What us nerds can use Google Analytics for, however, is error tracking via custom events.  Here's a quick look at how I've implemented error checking in analytics:

但这就是西装的全部内容,而不是我们的开发人员。 我们的书呆子可以使用Google Analytics(分析)来进行自定义事件的错误跟踪。 快速浏览一下我如何在分析中实施错误检查:


// 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.

现在,当您进入Google Analytics(分析)时,您可以查看自定义事件信息以及其他网站统计信息。 当然,您会告诉营销人员这些并不是真正的错误,它们是功能,但这是另一回事了。 考虑使用Google Analytics(分析)来跟踪网站错误-您稍后可以感谢我。

翻译自: https://davidwalsh.name/track-errors-google-analytics

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值