I want to use Google Analytics to monitor site speed. I pasted the code below in my HTML page:
<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>
In order to test it in my localhost, I use analytics_debug.js
instead of analytics.js
, UA-xxxxxxxx-x
as the real id, and domain.com
as the real domain name. siteSpeedSampleRate
is used to set the sample rate (see this link).
However, when my HTML page is visited, this JavaScript error happens when calling 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
You should use the following syntax:
Pass all option parameters within the
{}
and you should be fine.To test it on local host set the
cookieDomain
tonone
Read more about this here: https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#customizeTracker
Actually this is the solution:
Please, adjust your values accordingly.
As of 2014.01.02 this error message is standard in analytics_debug.js when it is sending a pagespeed timing beacon. Your code is fine / working corectly.