Tags: jquery, jquery plugin
When looking for an easy way to track outgoing links in Google Analytics with jQuery I came across this plugin. However, I needed a more flexible way of link tracking, with more control on which links to track and in what format.
For those reasons I use a small jQuery plugin written by Gerry Vandermaesen. Usage is simple:
$('a[rel=external]').gaLinkTrack();Of course you can modify the selector to your needs, but (for now) you can only track links.
Inside Google Analytics, the tracked link takes the format “/{rel}/{domain}/{page}” by default. If no rel attribute is present, it defaults to “external”. You can change the format of the tracked links by passing the path option:
$('a[rel=download]').gaLinkTrack( { path: '/downloads/{page}' } );When specifying the path format you can use any of the following placeholders: {rel}, {domain}, {page}. You can specify a default value for any of the placeholders (notably {rel}) as illustrated here:
$('a.download').gaLinkTrack( { path: '/{rel:download}/{page}' } );This is a first version so feedback and suggestions are more than welcome. Things still to come: proper handling of email links, more options for customizing the tracked path, and more…
Download the full source code (jquery-galinktrack-1.0.js) or the minified version (jquery-galinktrack-1.0.min.js).
Comments are closed.