J'essaie d'utiliser jQuery pour suivre les téléchargements et autres événements sur la page Web. Il est difficile de déboguer cela. Le code ci-dessous ne fonctionne pas actuellement. Supposons que la bibliothèque jQuery est chargée sur la page et que toutes les XXXX sont remplacées par les informations correctes. Des idées? TRÈS APPRÉCIÉE!jQuery Suivi Google Analytics
<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>
Il est difficile de déboguer, en partie, parce qu'il est si horriblement formaté. Vous devez rectifier ceci dans votre question, et dans votre code actuel si vous l'avez simplement copié et collé. – Bojangles
J'ai essayé votre code avec 'console.log' au lieu de' _gaq.push' et cela a très bien fonctionné. Probablement '_gaq.push (['_ setDomainName', 'XXXXX.com']);' contient un autre domaine que document.domain (par exemple, vous testez localhost). Cette discordance peut empêcher le suivi de google analytics. – CodingHamster
pour déboguer d'abord, vous devez remplacer tous les appels ** _ gaq.push() ** par ** console.log() ou alert(); ** - pour voir si votre code jQuery fonctionne correctement – shershen