I am kinda stumped as to how to track which links are the most popular on any given page on my site and would appreciate any advice or insight as to how to do this.
I am able to track the number of times a given resource (such as a web page) is requested from my site easily enough. I just pre-process every request running it through a tracking Perl script that writes the request and other info to a database. But these requests can come from inside my site or from outside as through a search engine. So this doesn't do me any good in terms of knowing how many times a given link on any given page is clicked relative to the other links on the same page.
I need some way to tell if a resource request (URL) is coming from inside my site or from outside. The HTTP_REFERRAL Apache environment variable is very unreliable and I do not want to depend on it.
About the only thing I could think of was to code all my site URL's and then to strip off the code into a normal URL after recording the click. So for example let's say I have a web page with a link on it. I could code the link as such...
<a href="/internal/new_page.html">Click here to go to the new page</a>
then my .htaccess file would direct to my tracking script like so...
RewriteRule ^internal/.*$ /cgi-bin/tracking.pl [L]
I would record the link from inside the tracking.pl script and then redirect to a regular URL without the "/internal".
It would seem that only those clicks that are intiated with "/internal" would be tracked (which is what I want in this case) and search engines and others would only see the URL's without the "/internal".
Any thoughts on the above or on a better way to do this?