我想使用 Google Analytics 来监控网站速度。我将下面的代码粘贴到我的 HTML 页面中:
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics_debug.js','ga');
ga('create', 'UA-xxxxxxxx-x', 'domain.com', {'siteSpeedSampleRate': 100});
ga('send', 'pageview');
</script>
为了在我的本地主机上测试它,我使用 analytics_debug.js
而不是 analytics.js
,UA-xxxxxxxx-x
作为真实 id,domain.com
作为真实域名。 siteSpeedSampleRate
用于设置采样率(参见 this link )。
但是,当访问我的 HTML 页面时,调用 ga('send', 'pageview')
时会发生此 JavaScript 错误:
Missing required field '"timingCategory"' for hit of type '"timing"' analytics_debug.js:8
log analytics_debug.js:8
O analytics_debug.js:7
b analytics_debug.js:15
Ec analytics_debug.js:15
nc analytics_debug.js:21
gc.(anonymous function).execute analytics_debug.js:19
ad.(anonymous function).send analytics_debug.js:45
Y.b.(anonymous function) analytics_debug.js:32
(anonymous function) analytics_debug.js:46
Sc analytics_debug.js:33
(anonymous function) analytics_debug.js:33
Missing required field '"timingVar"' for hit of type '"timing"' analytics_debug.js:8
log analytics_debug.js:8
O analytics_debug.js:7
b analytics_debug.js:15
Ec analytics_debug.js:15
nc analytics_debug.js:21
gc.(anonymous function).execute analytics_debug.js:19
ad.(anonymous function).send analytics_debug.js:45
Y.b.(anonymous function) analytics_debug.js:32
(anonymous function) analytics_debug.js:46
Sc analytics_debug.js:33
(anonymous function) analytics_debug.js:33
最佳答案
自 2014.01.02 起,此错误消息在 analytics_debug.js 发送 pagespeed 计时信标时是标准的。您的代码很好/工作正常。
关于javascript - 设置了 siteSpeedSampleRate 的 Google Analytics Site Speed 有 JavaScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18956326/