Clicky: Instantly track all outgoing clicks

I've created a little Javascript library I'm calling Clicky (get it here), that when inserted into a page it will automatically log the external links your users click. It requires no special server, client or reporting software. Clicky logs the clicks right to your own web server log file, so if you have access to your log then you can use Clicky. And the coolest thing is it will not break the link, so you don't have to worry about things like redirect scripts breaking or servers going down, it's unlikely to break the users experience under any cirumstances.

So, for example, if someone clicks this link Poo Poetry, before loading the new page Clicky will attempt to load an image (for approx. 1 second) at the following url:

http://damienkatz.net/clicky/link:http://poopoetry.com
--text:Poo%20Poetry?stamp=1111004763457

Which will leave a record in my server's log file. I can then view this information using Webalizer, AwStats or whatever log reporting tool I wish.

Here is a bit of what the clicks for Boing Boing looks like in Webalizer:

In this example it Clicky registered 6 clicks for Boing Boing.

How to install Clicky:

Step One:
Upload clicky.js your webserver.

Step Two:
Add the following to your HTML, just before the closing body tag (</body>):

<script type='text/javascript' src='/YOUR/UPLOAD/PATH/clicky.js'></script>

You are done!

Ok, not quite. There is one more thing you probably want to do, since by default these Clicky urls will show up a 404 errors in your log file, which means the reporting tools will treat the data differently. If you are using Apache you can fix it by creating an empty file named blank.txt adding the following to your .htaccess file:

RewriteEngine On
RewriteRule ^clicky/(.*)$ blank.txt

The "RewriteEngine On" line is only necessary once, so if it's already in the file don't add it again. If you aren't running Apache then you can modify other variables in the library and have Clicky report to a different url path, such as a CGI script. See the script for more details.

How does Clicky work?

It simply listens for all left clicks on the page where it's loaded. If someone clicks a link that will lead offsite, Clicky will encode the click information into a special url and attempt to load that URL from your site. It waits for about a second (to give time for it to make the request) then it returns and finishes executing the event normally. In this time, it should have made a successful connection to your server to load the image, which will cause the url request path to get logged. If it fails, then the click doesn't get recorded, but the user still gets to visit the link normally.

What if the browser doesn't have Javascript?

Then the page loads normally and nothing unusual happens. Clicky simply doesn't activate and the user's clicks don't get reported.

What if the Clicky code is broken or something goes wrong?

If the Clicky code encounters any error, it will simply abort itself and let the click event continue normally. The user won't see any errors.

Credit

I got the idea for Clicky when I saw this service MyBlogLog, which basically does the same thing but the clicks get reported to them, and they track and report the information for you. When I figured out how their library worked, I decided to write my own version that logs to my server. If you can't use Clicky for some reason, then you may be able to use MyBlogLog.

Clicky is in the public domain. Have fun.

Posted March 17, 2005 10:05 AM

Comments

A very nice solution, though I'm pretty sure that even the mod rewrite stuff could be bypassed by requesting a standard default image and passing the URL as a [harmless] query string, eg:

http://damienkatz.net/clicky.gif?link=http://poopoetry.com&text=Poo%20Poetry&stamp=1111004763457

which should return the image successfully, but will go into the server log with the full query string

mark, March 18, 2005 1:07 PM

ah whoops, I see from your example that the query string is perhaps NOT maintained when viewing stats in Webalizer... [it does get recorded in the log files though]

mark, March 18, 2005 1:10 PM

You are correct, I don't put the all the click information into the query string because the reporting tools always truncated it off. But that's just the default, I made it easy to change to whatever works best with your setup..

Damien, March 18, 2005 3:37 PM

I've installed clicky, even took the extra blank.txt step, but I'm not seeing its records in my tracker, AXS (http://xav.com/scripts/axs/).

Can you tell me how to get it to work for AXS?

Jennifer, April 5, 2005 7:02 PM

Sorry, AXS seems to be a proprietary server add on. Clicky is meant to log to a standard web server log. I don't think AXS can play with Clicky without some coding work.

Damien, April 8, 2005 5:49 PM

Hi!
I was googling for something like this script at least for 2 days! Great tool actually!

I have 2 comments:
1. I use this tool for tracking people as well as inside my website as well as outgoing clicks. So, there a little change in the code.
2. The script needs to be "hacked" a bit in order to write clicks on the links, which open new widnow with windows.open() script and empty href.

Yukko, November 20, 2005 5:08 PM

And one more thing. It doesn't work with Javascript counters placed on the page.

Yukko, November 20, 2005 5:38 PM

Hi,
Is there any way to make the script also record the links not actually CLICKED, but activated using the keyboard or manually entered into my browser's "Open URL" field? I would like to know this because as for me, I am blind and I never click anything on a web page. Instead I navigate the Internet using my keyboard so I probably never make JavaScript run an OnClick Event.
I was trying to replace "onclick" by "onunload", but I guess it is not that simple - because it did not work at all :-(

Anonymous, January 16, 2006 12:23 PM

Sorry Anonymous, I don't know enough about web development to answer your question.

Damien, January 16, 2006 1:21 PM

Hey Damien,

How would I go about implemeting this into a ColdFusion server? This looks like an extremely useful tool for any website. Let me know.

~Madison

Madison, January 19, 2006 11:49 PM

Cool script. Thanks! Does anyone know how to trap a middle click? like you use in Firfox to open a page in a new window.

Cheers

Peter, February 9, 2006 9:52 AM

Hi

I'm impressed by what your tool can do. I'm not a fulltime web programmer but manage to get some bits and tweak here and there.

I have a webpage on geocities.com. I would like to track all the clicks for the links on this page and write them to a comma separated csv file. This will help me run some reports.

Can you help me with this ?

Thanks
Rajeev

Rajeev, March 21, 2006 6:09 AM

Hey nice script, one question - does this track outgoing adsense links?

piniyini, June 28, 2006 9:36 AM

No, clicky cannot track adsense clicks. Sorry.

Damien, June 28, 2006 2:17 PM

Hi, quick question... Can i setup click to use rediect (google redirect) to off site pages..

The url would be replaced on the fly... example below

http://externallink.com
http://redir.com/script.php?url=http://externallink.com

Usman, September 9, 2006 2:00 PM

Sorry Usman, there is no way to configure it to do that.

Damien, September 9, 2006 7:37 PM

Post a comment




Remember Me?

(you may use HTML tags for style)