Mobile app version of vmapp.org
Login or Join
Jessie594

: Cross domain tracking - Wordpress and Google Analytics Which is the best approach to automatically add the _link GA action to every outbound link that points to a certain domain? e.g. <a

@Jessie594

Posted in: #GoogleAnalytics #Wordpress

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

e.g.

<a href="http://example.com/intro.html" onclick="_gaq.push(['_link', 'http://example.com/intro']); return false;">See my blog</a>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

1 Comments

Sorted by latest first Latest Oldest Best

 

@Tiffany637

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){
event.preventDefault();
_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]);

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme