admin管理员组文章数量:1308419
I am geting _gaq is undefined error in IE7 and IE8
My Script is bellow
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX']);
_gaq.push(['_setDomainName', 'yyy']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics/ga.js?';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Can I assign default value for _gaq? Refer this link
I am geting _gaq is undefined error in IE7 and IE8
My Script is bellow
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX']);
_gaq.push(['_setDomainName', 'yyy.']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics./ga.js?';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Can I assign default value for _gaq? Refer this link
Share Improve this question edited May 23, 2017 at 11:48 CommunityBot 11 silver badge asked Nov 15, 2012 at 6:15 Dharmalingam ArumugamDharmalingam Arumugam 40711 silver badges25 bronze badges 4- 1 that what's happening (setting a default) with var _gaq = _gaq || []; either it's taking current _gaq or it's creating an empty array. there must be something else wrong with your code. can you post some more? – Asken Commented Nov 15, 2012 at 10:29
- At which line you get _gaq is undefined? var _gaq = _gaq || []; is supposed to prevent that. – vinczemarton Commented Nov 15, 2012 at 10:30
-
1
Agree with above ments, the error isn't ing from this code, more likely from some other that references it. Is this script defined in the
<head>
section of your HTML? In older versions of GA you would put the script just before the closing</body>
tag. If it's still there, that's likely the issue. As long as the script tag has been read and processed before the_gaq
variable is referenced, you should not get this error (even from IE7 and IE8!!). – Tom Harrison Commented Nov 16, 2012 at 3:50 -
@tharrison: I added the script before
</body>
– Dharmalingam Arumugam Commented Nov 16, 2012 at 13:01
1 Answer
Reset to default 7Based on your reply to my ment, the answer to this question is
Google Analytics moved to a new, more modern way of handling events several years ago, allowing browsers to load a plete page without having to wait for a response from the GA servers. Whereas in the past, you were guided to put the <script>
snippet provided by google near the end of the page (just before the closing body tag), now you should instead include the tag somewhere in the <head>
section of your HTML.
The new script works by defining a javascript variable _gaq
as an array, that is treated like a queue. Pageviews, events and other stuff you want to track is pushed onto the array, which is effectively instant. When there is time, the GA code will check the array for contents and pop them off, processing the requests to the GA server until the array is empty.
A side effect of the _gaq
variable is that the script tag must be in the HTML before it is referenced, or else you'll get the JS error _gaq is undefined
.
For example as documented here in the Google Analytics event tracking guide you might want to know when a user plays a video on your site like this:
<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a>
Notice the reference to the variable _gaq
here. If not defined already, you'll get the error.
Short answer: put the async javascript snippet in the <head>
of your HTML.
本文标签: javascriptquotgaq is undefined” Google Analytics Error in IE7 and IE8Stack Overflow
版权声明:本文标题:javascript - "_gaq is undefined” Google Analytics Error in IE7 and IE8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741861129a2401628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论