Here’s a sweet bit of code I found to not only cloak affiliate links with php, but also count the clicks:
The nice thing about this bit of code is that you can add an unlimited amount of links to the one file. I’ve set this up (5 minute job) and it works like a dream. If you know how to create a database, you’ll have this up and running lickety split.
- You don’t have to buy a link cloaker/click tracker for *each* domain. This is a free solution, simply install the script for each site if you like.
- Redirects & tracks more than one link at a time.
- You could also install this on one single domain and use it as your own personal tinyurl for all your sites. Potential problem with that idea: it will be easy to trace all the domains in your network.
To view your click counts, you just have to go into phpmyadmin, select the database, select the linkcount table and then browse–each link name and count is displayed.
If you want to prevent the search engines from spidering those links (does Google view affiliate links as paid links?), just block them in robots.txt with:
That is all it takes. From here you may want to write a front-end to display your click results or you could even display the count next to the specific link in your sites navigation menu to rank the most popular outgoing links.
Maybe if we harrass studge.com we can get him to whip up that front end too for us non-codeheads so we don’t have to dig around in phpmyadmin :P. If you use his code, why not drop him a comment or a link as thanks, it’s a keeper.
ETA: Patrick pulled through with some more code–wooohooo! You’ll find the code to view the stats here: Displaying Click Counts with PHP and MySQL. Works GREAT, a big thanks to Studge.com!
Update: For WordPress users, there’s this handy plugin that will auto-cloak keywords that you set inside the WordPress admin panel (watch video to see how it works).