WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Google Analytics for WordPress] Does this pluging use the new Events Tracking feature? (2 posts)

  1. jmesam
    Member
    Posted 5 years ago #

    There is a new way to track outgoing links and downloading files:
    _trackEvent.

    With this new feature every click on an outgoing link don't count as page view, but count as a new Event "Outgoing link".

    In this blog there's a jquery code to track events:

    For outbound clicks

    $('a').click(function() {
      var $a = $(this);
      var href = $a.attr('href');
    
      // see if the link is external
      if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
    
        // if so, register an event
        var category = 'outgoing'; // set this to whatever you want
        var event = 'click'; // set this to whatever you want
        var label = href; // set this to whatever you want
    
        pageTracker._trackEvent(category, event, href);
      }
    });

    For file downloads

    var fileTypes = ['doc','xls','pdf','mp3'];
    
    $('a').click(function() {
      var $a = $(this);
      var href = $a.attr('href');
      var hrefArray = href.split('.');
      var extension = hrefArray[hrefArray.length - 1];
    
      if ($.inArray(extension,fileTypes) != -1) {
          pageTracker._trackEvent('download', extension, href);
      }
    
    });
  2. Joost de Valk
    Member
    Posted 5 years ago #

    Not yet, most importantly because you can't use events as goals yet... But I'll consider adding it in soon.

Topic Closed

This topic has been closed to new replies.

About this Topic