November 30, 2010

How to make a functional Amazon Associates link from generated "link to this page" code that will actually validate

I like to run blog posts through the W3C Validator. It catches a few errors and typos that may cause trouble down the line. But some auto-generated code can cause the validator to throw so many errors that it's difficult to see what I need to fix. Amazon Associates' link generator is something that has frustrated me plenty for the few times I've used it. Just inserting one link on a previously valid page will throw 10 errors and 15 warnings. But I think I've found a solution.

First, I want to make a couple of things perfectly clear. (A) I'm only posting this because I've figured it out twice, and couldn't find the answer on the internets when I forgot what I learned the first time and (B) yes, I realize it's only a cheatey little hack that just tricks the validator, but I don't care. Amazon will do what they do, and I don't really feel like wasting time researching the issue when Amazon obviously doesn't care about clean code. Plus, I want to make sure I make a little money when someone buys stuff because I made a well reasoned and insightful argument as to why they should.

The following assumes that you know something about both Amazon Associates and html. If not, go learn about them and come back later.

In brief, the answer to this dilemma is to use TinyURL. That's it, problem solved. For details, keep reading.

When I signed up for the Amazon Associates program a couple of years ago, I was encouraged to install their little toolbar in my browser. This toolbar has a purportedly helpful button that allows you to create a link to whatever Amazon page you are currently on. This link has your id code attached to it, so you'll get paid if someone visits the link and then buys the merchandise on the page.

The only problem with this method is that the rather ugly generated code will cause so many errors in the validator that it becomes a huge mess to sort out. I tried for a while to get the code to validate, but I couldn't get both the validator and Amazon's link checker to both work at the same time. However, both are happy if I just replace the target url with the TinyURL equivalent. In other words, translate the contents of the url within the first set of quotation marks after <a href= and you're good to go.

Let me know if you don't follow my reasoning here. It wouldn't be the first time I've been a bit obtuse.

Posted by Hal Eckhart at November 30, 2010 07:53 AM
Comments
Post a comment
spam and annoying comments will be deleted







Remember personal info?




enter this number security code in the box below (prevents comment spam)