web-dev-qa-db-fra.com

Google Analytics pageTracker n'est pas défini?

Un peu confus ... J'essaie de suivre les liens mailto sur lesquels on clique, mais constamment "pageTracker n'est pas défini" est affiché. J'ai le code suivant juste avant ma balise de fin de corps ()

<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>

Ensuite, j'utilise ceci dans mes liens mailto

<a href="mailto:[email protected]" onClick="javascript:pageTracker._trackPageview('/mailto/hello');">[email protected]</a>

Je ne vois pas pourquoi ça ne marche pas? Toute aide serait appréciée

34
leen3o

Le nouveau code Async Google Analytics (que vous utilisez) fonctionne un peu différemment du non-Async. Chaque fois que vous souhaitez appeler une méthode sur pageTracker, il vous suffit de pousser un "message" dans la file d'attente "_gaq".

<a href="mailto:[email protected]" onClick="_gaq.Push(['_trackPageview', '/mailto/hello'])">[email protected]</a>

Bien que le suivi d'un lien mailto puisse mieux fonctionner en tant qu'événement:

<a href="mailto:[email protected]" onClick="_gaq.Push(['_trackEvent', 'mailto', 'home'])">[email protected]</a>

Pour plus d'informations, consultez le Async Tracking Users Guide .

75
joshperry

On peut également ajouter:

//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();

dans le nouveau code pour conserver l'ancien code dans les pages.

20
Merlinox

Voici le code:

onClick="_gaq.Push(['_trackEvent', 'pdf', 'download', '/pdf/myPdf'])">myPdf</a>
3
Nanda

J'avais aussi besoin d'un moyen de résoudre le téléchargement de PDF et voici ce que j'ai utilisé:

<a href="http://www.domain.com/assets/downloads/filename.pdf" target="_blank" onClick="_gaq.Push(['_trackEvent', 'Downloads', 'Download', 'Price Brochure PDF'])">Download Brochure</a>

Pour plus d'informations sur _ trackEvent , voici la page Doc API

1
Osura