I've got as far as creating the tracking and it works great like so:
$('a.external').click(function(){
_gaq.push(['_trackEvent', 'Exit Links', 'Click', $(this).attr('href')]);
});
<a href="http://example.com" class="external">example</a>
This comes through to analytics correctly with the href as the label. What I'm wanting to do is be able to tag the current page they are on as well. So we can work out which page they were on when they clicked the link to go to an external page.
Something like this?
$('a.external').click(function(){
var pathName = window.location.pathname + document.location.hash;
alert(pathName);
_gaq.push(['_trackEvent', 'Exit Links', 'Click', $(this).attr('href')] pathName);
});
That alerts the correct location but could anyone help me clean it up so that the pathName is added to the label within the gaq.push?
Thanks!
Sean