0

I have an external link which links to my site and i would like to track the number of clicks on that link.

One way to do it without using google analytics is to use ajax as mentioned in this post : How do I keep track of how many times an external link is clicked? (See the first response)

But if I use JavaScript the number of clicks can easily be faked. What is the best way to prevent this?

Edit: sorry I didn't make my question clear. Just like the like button in fb for instance, the user who visits my site can get a link (which he/she has to copy/paste) and the link will point to my site.

Community
  • 1
  • 1
user1285659
  • 123
  • 1
  • 11
  • Use a cookie, and put in it all the links that have been clicked. Of course, one can clear the cookies and hack it. – Candide Oct 21 '13 at 08:00
  • exact count can only be taken of a logged in user ,but you can use cookies to get a rough idea – Arun Killu Oct 21 '13 at 08:01

1 Answers1

0

You could implement a server side script is a middleware that logs the click before it redirects.

E.g you have a simple PHP script like this:

<?php
$url = $_GET['url'];
$logger->logHit($url);
header("Location: ".$url);
?>

Then you link would be something like this:

http://yoursite.com?url=http://external.com
subZero
  • 5,056
  • 6
  • 31
  • 51
  • Just like this, this is a hacker paradise code snippet. You have to verify that the URL is not tainted, which in general means that you do not want to redirect anyone anywhere other than a set of given destinations. If anything is attempted, you have to drop the request. Unfortunately, there are very many such code snippet on the Internet... – Alexis Wilke Jan 12 '15 at 00:55
  • Alexis, The code above is provided merely as a proof of concept, and serves to exemplify a method and approach that can be taken if you so desire. If you, as a developer, search Google for code snippets and so chose to use what you find, it is YOUR responsibility to make sure the code is SAFE for YOUR needs. Unfortunately, there are many such "developers" who blindly copy/paste whatever they find online and expect it to work. This is not how software development in practice functions. – subZero Jan 13 '15 at 07:59