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 ()
有点困惑......我正在尝试跟踪被点击的mailto链接,但不断显示'pageTracker未定义'。我在我的结束体标记之前有以下代码()
<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
然后我在我的mailto链接中使用它
<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
我不明白为什么它不起作用?任何帮助,将不胜感激
4 个解决方案
#1
75
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.
新的Async Google Analytics代码(您正在使用的)与非Async的工作方式略有不同。任何时候你想在pageTracker上调用一个方法,你只需将“消息”推送到“_gaq”队列。
<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:
虽然,跟踪mailto链接可能会更好地作为事件:
<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.
有关详细信息,请参阅“异步跟踪用户指南”。
#2
20
We can also add:
我们还可以添加:
//mantain syntax between old and new asynch methods
//http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#Syntax
function _pageTracker (type) {
this.type = type;
this._trackEvent = function(a,b,c) {
_gaq.push(['_trackEvent', a, b, c]);
};
}
var pageTracker = new _pageTracker();
in new code to mantain old code in pages.
在新代码中保留页面中的旧代码。
#3
3
Here is the code :
这是代码:
onClick="_gaq.push(['_trackEvent', 'pdf', 'download', '/pdf/myPdf'])">myPdf</a>
#4
1
I needed a way to tack downloading PDFs too and heres what I used:
我需要一种方法来处理下载PDF文件,并且我使用的是:
<a href="http://www.domain.com/assets/downloads/filename.pdf" target="_blank" onClick="_gaq.push(['_trackEvent', 'Downloads', 'Download', 'Price Brochure PDF'])">Download Brochure</a>
For more info about _trackEvent, heres the API Doc page
有关_trackEvent的更多信息,请参阅API Doc页面
#1
75
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.
新的Async Google Analytics代码(您正在使用的)与非Async的工作方式略有不同。任何时候你想在pageTracker上调用一个方法,你只需将“消息”推送到“_gaq”队列。
<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:
虽然,跟踪mailto链接可能会更好地作为事件:
<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.
有关详细信息,请参阅“异步跟踪用户指南”。
#2
20
We can also add:
我们还可以添加:
//mantain syntax between old and new asynch methods
//http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#Syntax
function _pageTracker (type) {
this.type = type;
this._trackEvent = function(a,b,c) {
_gaq.push(['_trackEvent', a, b, c]);
};
}
var pageTracker = new _pageTracker();
in new code to mantain old code in pages.
在新代码中保留页面中的旧代码。
#3
3
Here is the code :
这是代码:
onClick="_gaq.push(['_trackEvent', 'pdf', 'download', '/pdf/myPdf'])">myPdf</a>
#4
1
I needed a way to tack downloading PDFs too and heres what I used:
我需要一种方法来处理下载PDF文件,并且我使用的是:
<a href="http://www.domain.com/assets/downloads/filename.pdf" target="_blank" onClick="_gaq.push(['_trackEvent', 'Downloads', 'Download', 'Price Brochure PDF'])">Download Brochure</a>
For more info about _trackEvent, heres the API Doc page
有关_trackEvent的更多信息,请参阅API Doc页面