Posted By

theroamingcoder on 01/18/10


Tagged

jquery Analytics clicks trackEvent


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

legacye
timpreneur
Balamir


Google Analytics - jQuery - track all outbound link clicks


 / Published in: JavaScript
 

This code uses jQuery to add on onclick event tracker to all the links in a specific section of the page. Can easily be modified for additional uses. Note that this does not use the custom page view tracker like mentioned here : http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527 so that it does not skew your actual page views count.

  1. <script type="text/javascript">
  2. <!-- ga tracking for offsite links clicks -->
  3. $(function(){
  4. $("#block-menu-secondary-links .content .menu li a").each(function(){
  5. $(this).click(function () {
  6. if(pageTracker != undefined){
  7. pageTracker._trackEvent('Offsite Links', 'Click', $(this).attr("href"));
  8. }
  9. });
  10. });
  11. });
  12. </script>

Report this snippet  

You need to login to post a comment.