The method most sites use for this is to have a script on your site handle the redirect. So instead of the link being directly to:
http://websiteB.com
the link goes to something like:
http://websiteA.com/link/websiteB.com
The "link" script logs the request and then forwards them to the address (this should be done instantly, don't give them a "forwarding you to Website B in 3 seconds!" page).
Note that as a visitor to your site, I much prefer a method where the link's destination is apparent when I hover over the link, as opposed to the method that some sites use where all you see is an id. What I mean is, instead of the link being something like:
http://websiteA.com/link/websiteB.com
they instead have a link like:
http://websiteA.com/link/483
Showing the destination can be achieved in a few ways. One way is something like I described above, where the destination is part of the query string. Alternatively, you can use some Javascript for this. The status bar's value can be changed with Javascript by setting the window.status
variable, but many browsers prevent this by default (Firefox, for example).
Google has found a sneaky way around this problem by actually using Javascript to change the link instead of the status bar. When the page is loaded, the links in the results list go to their actual destinations, but every link has an onmousedown
javascript event that changes the link when you click on it. You can see this in action by right-clicking on a link. After you've done that, hovering over the link will now show the true destination (Google's click-tracking script) in the status bar instead of the result's real URL.
Of course the information displayed with any method could be a misrepresentation of where I'm actually going to be sent, but I still prefer it over seeing a meaningless id number.