我想使用谷歌分析来监控网站速度。我将以下代码粘贴到我的 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>
为了在我的 localhost 中测试它,我使用analytics_debug.js
代替analytics.js
,UA-xxxxxxxx-x
作为真实 id 和domain.com
真实域名。 siteSpeedSampleRate
用于设置采样率(请参阅此链接)。
但是,当访问我的 HTML 页面时,调用时会发生此 JavaScript 错误ga('send', 'pageview')
:
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