我想使用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>
Run Code Online (Sandbox Code Playgroud)
为了在我的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"' …Run Code Online (Sandbox Code Playgroud)