Search Engine Friendly Exit Counter

Multithreaded JavaScript has been published with O'Reilly!
DEPRECATED: This post may no longer be relevant or contain industry best-practices.

We built this script about a month ago that counted the exit clicks with affiliates. The url for the script (which, if your reading this, your probably familiar with) is /exit.php?go=### where ### is the unique id for each affiliate.

The problem with this script is that it is not search engine friendly. The exit.php, as you can probably guess, spits out a meta refresh tag that redirects the user to the affiliate site. Google doesn't like the meta refresh tag. Therefore, by using that system, we don't help out our affiliates. Google will simply see the link to a page called exit.php and ignore everything.

Google follows plain boring anchor links (<a href="www.com">www</a>) and uses the title attribute to help index the link. Google does not follow javascript links. Well, if Google doesn't follow them, why is this tutorial mentioning them? All you need to do to make a search engine friendly link is place the javascript link inside of the normal anchor tag.

Here is the code:

<a href="http://www.google.com/">
<img src="affiliates/google.gif" alt="Google" title="Google"
 onclick='window.location="exit.php?go=25"'>
</a>

The anchor tag encompasses the image tag. The anchor tag links to the normal website. The image tag has the onclick attribute which links to the affiliate script.

Why this works: Google is parsing the vanilla anchor tag, and the user's browser, when the affiliate image is clicked, decides to follow the onclick instead of the anchor. Google is happy and see's their normal link to another site, the user is happy as they see the normal exit url link when hovering over the link, and the webmaster is happy because they can track the exit counts.

Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.