Steve Lacey. Get yours at flagrantdisregard.com/flickr

Tracking Clicks

| | Comments (0) | TrackBacks (0)

Being a bit of a neophyte (well, maybe I'm a journeyman now) to javascript, I have been tracking the links that users click on in my AJAX homepage site by having the URL for the link be something like http://www.memeflow.com/goto/goto.php?hit=234, which after noting the hit would redirect to the requested page. Rather cryptic and problematic.

The problem is that this url is what shows up in the status bar, not the url for the site that the user is expecting to navigate to. The other problem is that you can't right-click on it to copy the url to the clipboard.

So, along comes various threads on message boards about google tracking clicks by rewriting the url on the 'onmousedown' event. Very sneaky and very clever.

I've told users that I'm tracking the clicks since day one, so this isn't a problem for me. So now, the url for each link is exactly the correct link for the site the user is expecting to visit, but the element has this attached to it for the 'onmousedown' event.

this.nodeItem.onmousedown = function(evnt)
{
    var left = true;
    if ((evnt) && evnt.which)
    {
        if (evnt.which != 1)
            left = false;
    }
    else if (event && event.button)
    {
        if (event.button != 1)
            left = false;
    }
    if (left)
        this.setAttribute('href', 'goto.php?hit=' + id);
}

Most of that code is actually checking to make sure the click was from the left button, so that a right mouse-click has the desired behaviour.

I hope someone finds this useful...

0 TrackBacks

Listed below are links to blogs that reference this entry: Tracking Clicks.

TrackBack URL for this entry: http://www.steve-lacey.com/cgi-bin/mt/mt-bar.cgi/540

Leave a comment

About Me

Steve Lacey, software developer at Facebook, British, married to the lurvely Nabila, dad to the wonderful Julian and Jasmine. Living in Kirkland (near Seattle), WA.


A brief professional bio.


steve@steve-lacey.com
+1 (425) 214-4716

About this Entry

This page contains a single entry by Steve published on August 31, 2005 3:25 PM.

Boeing Blogging Flight Tests was the previous entry in this blog.

Backward Compatibility In Flight Simulator is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Statsorama

  • 1050 posts
  • 1333 comments

Music