Which is the best approach to automatically add the _link GA action to every outbound link that points to a certain domain?


<a href="http://example.com/intro.html" onclick="_gaq.push(['_link', 'http://example.com/intro']); return false;">See my blog</a>
  • How would you normally add an onclick event handler?
    – MrWhite
    May 15, 2013 at 7:41

1 Answer 1


You can add an event handler to all links that point to a specific domain.

For example if the domain you are linking to is example.com and jQuery 1.0+:

var linksToHost = $('a').filter(function(){
    return this.host.match(/^example\.com$/);

linksToHost.bind('click', function(event){
    _gaq.push(['_link', this.href]);

You must also enable linking on the target site in order for link to work properly: _gaq.push(['_setAllowLinker', true]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.