How to track clicks on outbound links

后端 未结 3 1385
栀梦
栀梦 2021-01-28 23:48
[cross-posted on Google Products Forum http://productforums.google.com/d/topic/analytics/ZrB14a-6gqI/discussion ]

I am using the following code at http

3条回答
  •  庸人自扰
    2021-01-29 00:46

    Here's what I'm using, which has been working for me. I'm using jQuery to add the onclick handler to any link with a class of "referral", but I'd expect adding it directly in the HTML to work as well.

      $(function() {
        $('.referral').click(function() {
          _gaq.push(['_trackEvent', 'Referral', 'Click', this.href]);
          setTimeout('document.location = "' + this.href + '"', 100);
          return false;
        });
      });
    

    edit: I believe your syntax for invoking a tracker by name is wrong. Since you aren't using a named tracker when you set up tracking at page load, you shouldn't try to name it later either. See the documentation for _gaq.push.

    More precisely:

    1. The var myTracker declaration is unused, so you can just delete that line. Variables declared within the scope of recordOutboundLink aren't visible when other functions, such as _gaq.push, are running, so it can't be relevant.
    2. You should simply use '_trackEvent' instead of 'myTracker._trackEvent'.

提交回复
热议问题