Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics code, how does it work?

From here: http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1136920

<script type="text/javascript">
function recordOutboundLink(link, category, action) {
  try {
    var myTracker=_gat._getTrackerByName();
    _gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
    setTimeout('document.location = "' + link.href + '"', 100)
  }catch(err){}
}
</script>

If you notice the + category + and + action + are in quotes. So how does the analytics script gets their values?

like image 489
mbdev Avatar asked Nov 04 '22 10:11

mbdev


1 Answers

It's a mistake in their documentation; their code will not work as intended.

That line should read:

_gaq.push(['myTracker._trackEvent',  category ,  action ]);

You're right. The way they have it, it has category and action passed as literal strings, rather than passing the variables that hold the strings in them.

like image 150
Yahel Avatar answered Nov 09 '22 09:11

Yahel