The following message appears when viewing a site page in the chrome debug log.
Uncaught ReferenceError: _gaq is not defined
The page itself is supposed to track an object using the onload
event handler and fire a _trackEvent
for Google Analytics.
My best guess is that perhaps the ga.js
file doesn't load in time and therefore the onload
_trackEvent
triggered is not caught. the async snippet is being used before the </body>
close and the object is positioned in the middle <body>
.
(some other posts have referenced jQuery position too but, this might be a red herring)
any assistance greatly appreciated.
Had the same problem. You have to define the
_gaq
array. Just add this after your Google Analytics script in the header:You can use the last version of analytics.js instead of ga.js
Here is an example:
Change the Tracking Code to:
Regarding the position of the async snippet, the GA help page says -
My first thought was that JS should be loaded at the bottom of the page to improve page speed. However, the GA async tracking snippet should be loaded in the head, as it will not load the ga.js immediately, and it won't block page execution.(It does this by dynamically adding the script tag to the DOM, which puts it at the back of the queue.)
If, for some reason, you can't move the async snippet to the head, you can define
_gaq
yourself, like this-From https://developers.google.com/analytics/devguides/collection/gajs/ this code replaces your existing "traditional snippet" with the "latest, asynchronous version, you should remove the existing tracking snippet first."
To see your events come in (to know if this is working) look for "Events" under the "Real-Time" menu option on the left side of the "Reporting" page.