How can i detect external link click?
I have a simple question, which may or may not have an simple answer. I need to detect if some of my page's user's have clicked an external link, an ad for example.
My first tought was that i would place an random number of transparent div's over a specific link so an user should click on it until he'll get redirected to a new page but that would be inconvievnant for users and would still be exploitable.
I hope that you guys can help me out and i'll do my best to help you out one day.
Sorry for my english as my native language isn't english.
with jquery, select all external links and an handler for click event:
// Creating custom :external selector
$.expr[':'].external = function(obj){
return !obj.href.match(/^mailto\:/)
&& (obj.hostname != location.hostname);
};
// Manage clicks on external links
$('a:external').click(function() {
// do your stuff here, ie send the link href to some server-side script
$.ajax({ type: "POST", url: "some.php", data: "href="+$(this).attr("href") });
});
Hey, you really need to use google analytics. Incase you do not want to do that, check this out. Logging hyperlink clicks on my website
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With