While searching the web for a proper way to track user behaviour, I stumbled upon a very interesting blog post written by Brian Cray. He uses the „power“ of Google Analytics‘ new Asynchronous Tracking to track all clicked links and get information about how the users behave on his site. This method gives you insights about what elements of the site are really used and how the visitors are navigating through the content. Brian sums it up quite properly:

I dare you to answer the following questions with your current Google Analytics setup:

  • Are your users using the main menu to navigate or do they use different means to find content?
  • Do your users scroll through your content and click links in the footer?
  • Do your users click on an article title or the “continue reading…” link?
  • Do your users actually go through the items in my dropdown menu, or are they
  • unaware of the dropdown menus?
  • Do your users follow your related blog entry suggestions?

As I’ve chosen Mootools as the Javascript-Framework for many of my websites, I couldn’t really copy and paste the code to the <head>-sections. I’ve not only rewritten the code-snippet to utilize Mootools instead of jQuery but also tweaked the functionality which results in better tracking.

Just copy and paste this right under the code of google analytics:

window.addEvent('domready', function() {
	$$('a').addEvent('click', function(event){
	  	var element = $(event.target || event.srcElement);

		if(element.get('tag') != 'a'){
			element = element.getParent('a[href]');
		}

	  	try{
	  		_gaq.push(['_trackEvent', (element.get('id') || element.getParent('[id]').get('id')), 'clicked', (element.get('text').trim() || ((element.getFirst('img'))?element.getFirst('img').get('alt'):element.get('href'))) || element.get('href')]);
	  	}catch(err){
	  	}	  	

	});
});

For more information about how this works and asynchronous tracking in general, please visit Brian’s blog.

Kommentare

  • Pingback: Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery()

  • http://briancray.com Brian Cray

    Thanks for porting this script. I’ve added a link to this article on the entry itself =)

  • http://www.frankharper.de Frank

    Running Joomla 1.5.20 I added the code at the bottom of the block containing my (working) GA code – but my GA stats don’t show any events, didn’t matter wherever inside the or I placed it… any hint?

  • http://doorsmelbourne.org/ Doors Melbourne

    This site is actually actually exciting. You provide up several good details regarding the post. The idea will be my personal first time in this article inside this particular web page therefore high quality work.

    • http://113tidbits.com/ tonygreene113

      Have ou noticed that all of your comments are not linked?

  • http://veda3d.com RGhost

    This code not working well with „lightboxes“ in my case with http://iaian7.com/webcode/mediaboxAdvanced. This code allows google analytics only track next/prev buttons in the box windows but doesn’t track image name. Can you help with this?

  • http://113tidbits.com/ tonygreene113

    Google analytics misses a ton of info from visitors, especially if you don’t understand all the semantics of „url query“ and other parameters.

  • EricYHuang

    If you want to do individual visitor tracking in Google Analytics. you can check out our tool skyglue.com.  Just by copying one line JavaScript to your site, SkyGlue lets you see visitor behavior in full details. 
     
    The most valuable Google Analytics add-on.

    • http://113tidbits.com/ tonygreene113

       @EricYHuang I tried to sign up at skyglue and received numerous errors after attempting to merge into Google analytics…

      • EricYHuang

         @tonygreene113 Had some off-line communication with Tony. The account setup was fine even though there is an error message during setup. This is a „false error“.  It is caused by an empty response from Google Analytics API. This seems to be a rare case. We will watch for it.

      • EricYHuang

         @tonygreene113 Had some off-line communication with Tony. The account setup was fine even though there was an error message during setup. This is a „false error“ and seems to be a rare case. We will watch for it.

      • EricYHuang

        Had some off-line communication with Tony. The account setup was fine even though there was an error message during setup. This is a „false error“ and seems to be a rare case. We will watch for it.
         
         

        • EricYHuang

          test