«

»

Nov
28

jQuery/Google Analytics Script to Track Outbound Links

Usage

Assign link-outbound class to any trackable external links on the page. As scripted here, your outbound links will appear in Analytics as /outbound/ with the full URL of the outbound link appended. This can be modified to suit your reporting needs.

Example

External link:

<a class="link-outbound" href="http://www.externalsite.com">Link to externalsite.com</a>

Script block (assumes jQuery and Google Analytics are both loaded):

<script type="text/javascript">

<!--

$(document).ready(init);

function init() {

$('a.link-outbound').click(function () {

_gaq.push(['_trackPageview', '/outgoing/' + $(this).attr('href')])

});

}

-->

</script>

Leave a Reply