Forum Moderators: DixonJones
<A href="http://example.com"
onclick="location.href='myClickTracker.cgi'; return false;">
Click me click me click me!
</A>
When someone clicks the link then Javascript sends them over to the click tracking script, which then sends them to the destination site.
But the link remains clean, which is what advertisers want for SEO purposes.
If the user has Javascript disabled, it's okay, because the link still works.
This fails to count clicks for users with Javascript disabled, but to me that's more than made up for by the fact that I now don't have to filter out a buttload of bot clicks.
Maybe this is old news, but I seem to recall reading threads where people said that you can either track clicks, or have a clean link, but not both. So at least for anyone else besides me who didn't know it was possible to do otherwise, here ya go.
[edited by: Woz at 11:31 pm (utc) on Mar. 27, 2005]
[edit reason] examplified URL [/edit]
#!/usr/bin/perl -w
open (FILE, '<adcounter.txt');
@data = <FILE>;
close (FILE);
$theCount = int($data[0]) +1;
open (FILE, '>adcounter.txt');
print FILE $theCount;
close (FILE);
print "Location:http://YourAdvertiser.com\n\n";
This writes the count data to a text file called "adcounter.txt". Every time someone clicks the link as described in my first post, this script will add 1 to the number in the adcounter.txt file, then sends the visitor over to whatever URL you specify.