Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect external link Click?

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.

like image 779
Ardi Vaba Avatar asked Oct 21 '25 17:10

Ardi Vaba


2 Answers

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") });
});
like image 127
guido Avatar answered Oct 23 '25 05:10

guido


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

like image 39
Neeraj Avatar answered Oct 23 '25 06:10

Neeraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!