我正在尝试使用 jQuery 来跟踪网页上的下载和其他事件。很难调试这个。下面的代码目前不工作。假设页面加载了 jQuery 库,并且所有 XXXX 都替换为正确的信息。有任何想法吗?非常感激!
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX']);
_gaq.push(['_setDomainName', 'XXXXX.com']);
_gaq.push(['_addIgnoredRef', 'XXXXX.com']);
_gaq.push(['_trackPageview']);
if (jQuery) {
jQuery(document).ready(function () {
jQuery('a').click(function () {
var $a = jQuery(this);
var href = ($a.attr('href')) ? $a.attr('href') : '';
if ((href.match(/^http/i)) && (!href.match(document.domain))) {
var category = 'outgoing - XXXX Landing';
var event = 'click - XXXX Landing';
_gaq.push(['_trackEvent', category, event, href]);
} else {
if (href.match(/.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i)) {
var category = 'download - XXXX Landing';
var event = 'click - XXXX Landing';
_gaq.push(['_trackEvent', category, event, href]);
} else {
if (href.match(/^mailto:/i)) {
var category = 'mailto - XXXX Landing';
var event = 'click - XXXX Landing';
_gaq.push(['_trackEvent', category, event, href]);
}
}
}
});
});
}
(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';
if ('http:' == document.location.protocol) {
ga.src = 'http://www.google-analytics.com/ga.js';
} else {
ga.src = 'https://ssl.google-analytics.com/ga.js';
}
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>