Google Analytics pageTracker未定义? [英] Google Analytics pageTracker is not defined?
问题描述
< script type =text / javascript>
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-000000']); //这是我的帐号,我在这个编辑器中添加了零
_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.com / ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga,s);
})();
< / script>
然后我在我的mailto链接中使用这个
< a href =mailto:hello@mydomain.co.ukonClick =javascript:pageTracker._trackPageview('/ mailto / hello');> hello @ mydomain.co.uk< / A>
我看不出为什么它不起作用?任何帮助将不胜感激
新的Async Google Analytics代码(您正在使用)的工作方式与非-async。任何时候你想在pageTracker上调用一个方法,只需在_gaq队列中推送一个消息。
<< ; a href =mailto:hello@mydomain.co.ukonClick =_ gaq.push(['_trackPageview','/mailto/hello'])\">hello@mydomain.co.uk</a>
虽然跟踪邮件链接可能会更好地发挥作用:
< a href =mailto:hello@mydomain.co.ukonClick =_ gaq.push(['_trackEvent','mailto','home ])> hello@mydomain.co.uk< / A>
欲了解更多信息,请查看异步跟踪用户指南。
Little bit confused... I am trying to track mailto links being clicked, but constantly 'pageTracker is not defined' is shown. I have the following code just before my end body tag ()
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-000000']); // This is my account number, I have added the zeros in this editor
_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.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Then I am using this in my mailto links
<a href="mailto:hello@mydomain.co.uk" onClick="javascript:pageTracker._trackPageview('/mailto/hello');">hello@mydomain.co.uk</a>
I cannot see why its not working? Any help would be appreciated
The new Async Google Analytics code (that you're using) works a bit differently than the non-Async. Any time that you want to call a method on pageTracker you simply push a "message" onto the "_gaq" queue.
<a href="mailto:hello@mydomain.co.uk" onClick="_gaq.push(['_trackPageview', '/mailto/hello'])">hello@mydomain.co.uk</a>
Although, tracking a mailto link may work better as an event:
<a href="mailto:hello@mydomain.co.uk" onClick="_gaq.push(['_trackEvent', 'mailto', 'home'])">hello@mydomain.co.uk</a>
For more info take a look at the Async Tracking Users Guide.
这篇关于Google Analytics pageTracker未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!