The easiest Amazon Associate links yet

You’re an Amazon Associate, maybe you make a few dollars a month by linking to products you like, but you know you could make more if only it was easier to build the links. Or you’ve already found an easy way to automagically add your associate ID, but then you upgraded your blog or moved servers and broke all your links. I think I’ve got a great solution to both of those problems.

I like Brad Choate’s method, and I used a slightly modified version of that before I upgraded to 3.2. But during the upgrade I accidentally deleted my macros, and all my <amazon> tags became useless. At the time I was running TBOTCOTW as a dynamic blog, as well, and Brad’s code uses plugins that don’t work on dynamic pages (yet). On top of that, MTAmazon hasn’t been actively developed in years, and I wasn’t sure it would work with 3.2 at all. So I gave up and changed all my tags back to regular links to Amazon.com.

Then I switched back to static publishing found out that Byrne Reese developed MTAmazon32, so I wanted to start doing some macros again. I didn’t feel like changing all those links back to <amazon> tags by hand, so I decided to see if I could make things even easier. Could I take Brad Choate’s macros and make them interface with MTAmazon32 to add my associate tags to a vanilla HTML link to Amazon.com?

After banging at it for a couple of hours, I came up with a solution. First, you need the MTAmazon32, MTMacros, MTIfEmpty, and MTRegex plugins. Install them all according to directions (if you have issues with this step, just ask for help in comments).

Now create a template module in Movable Type called Macros. Put the following in that:

<MTRegexDefine name="amazon_fixup1">
s {^http://(www.)?amazon\.com/exec/obidos/tg/detail/-/([a-zA-Z0-9]+)/.+$} {$2}
</MTRegexDefine>
<MTRegexDefine name="amazon_fixup2">
s {^http://(www.)?amazon\.com/exec/obidos/ASIN/([a-zA-Z0-9]+)/.+$} {$2}
</MTRegexDefine>
<MTRegexDefine name="amazon_fixup3">
s {^http://(www.)?amazon\.com/gp/product/([a-zA-Z0-9]+)/.+$} {$2}
</MTRegexDefine>
<MTRegexDefine name="amazon_fixup4">
s {^http://(www.)?amazon\.com/exec/obidos/tg/browse/-/([0-9]+)/.+$} {http://www\.amazon\.com/exec/obidos/tg/browse/-/$2/tbotcotw-20?camp=2025&ink_code=xm2}
</MTRegexDefine>
<MTRegexDefine name="amazon_fixup5">
s {^http://(www.)?amazon\.com/exec/obidos/tg/stores/series/-/([0-9]+)/.+$} {http://www\.amazon\.com/exec/obidos/tg/stores/series/-/$2/tbotcotw-20?camp=2025&ink_code=xm2}
</MTRegexDefine>
<MTMacroDefine ctag="a" name="amazonfixup">
<MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http://(www.)?amazon.com/exec/obidos/tg/browse/-/.*|">
<MTMacroAttr name="href" value="[MTMacroAttr name='href' regex='m/^amazon_fixup.*/']">
</MTIfMatches>
<MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http://(www.)?amazon.com/exec/obidos/tg/stores/series/-/.*|">
<MTMacroAttr name="href" value="[MTMacroAttr name='href' regex='m/^amazon_fixup.*/']">
</MTIfMatches>
<MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http://(www.)?amazon.com/.*|">
<MTIfNotMatches expr="[MTMacroAttr name='href' regex='m/^amazon_fixup.*/']" pattern="m|^http.*|">
<MTAmazon search="[MTMacroAttr name='href' regex='m/^amazon_fixup.*/']" method="Asin">
<MTMacroAttr name='href' value='[MTAmazonLink]'>
<MTIfNotEmpty expr='[MTAmazonSalePrice]'>
<MTMacroAttr name='title' value='Buy &#8220;[MTAmazonTitle]&#8221; at Amazon.com -- only [MTAmazonSalePrice]!'>
</MTIfNotEmpty>
</MTAmazon>
</MTIfNotMatches>
</MTIfMatches>
<MTMacroTag rebuild="1"><MTMacroContent></a></MTMacroDefine>

Put the tag <MTInclude module=”Macros”> somewhere in the header of all your index templates, then turn on the macros by adding the apply_macros tag in the right places:

<$MTEntryBody apply_macros=”1″$>
<$MTEntryMore apply_macros=”1″$>

Even cooler, you can apply this to your comments: <$MTCommentBody apply_macros=”1″$>

This will search your entries (and comments) for links to Amazon.com, use MTRegex to grep out the ASIN, then use MTAmazon32 to build a new link to that product with your Amazon Associate information, and even puts the price of the product in a tooltip (and uses MTIfEmpty to avoid useless tooltips if Amazon isn’t publishing the price through they’re API). Now, instead of the old process of copying and pasting ASINs into Amazon’s hard-to-use link builder, all you need to do is copy and paste the entire Amazon URL into your post. Plus, you don’t have to remember how to use a proprietary <amazon> tag, and you can move your entries to another blog without changing anything. Everything is just a plain old link.

And if you apply this to your comments section, even links put in by your readers will have your associate tag. Perhaps it’s unethical to hack your readers’ links (I don’t think so, it’s your blog, after all), but it’s a nifty little hack regardless.

Basically, Brad’s solution turns tags that look like <amazon ASIN=”###########”> into links to Amazon’s site. But it’s a pain to copy and paste those numbers into the tag, and if you mess up you get a useless link. And then if you try to move that post to a blog that doesn’t have the same macros installed it just ignores it and you don’t have a link at all. Better to use standard links and hack those up before they’re written to the file.

Popularity: 4% [?]

2 Comments on “The easiest Amazon Associate links yet”

  1. I might also recommend that you try Media Manager (http://www.majordojo.com/projects/MediaManager) which is an advanced Movable Type plugin for managing lists of Amazon items. It fully integrates with Amazon’s Web services making it easy to maintain links of Amazon items, and ensuring that the links are constructed properly using your Amazon Associates ID (which is set easily through Movable Type’s settings interface). It comes with its own template tags as well, and a way to create reviews about items on your “Media Queue.”

     
  2. I haven’t tried Media Manager yet, it seemed like overkill for what I needed. I’ll take a look.

     

Leave a Reply