Search Engine Friendly Exit Counter

DEPRECATED: This post has been marked as deprecated and may no longer 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 is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.