Editor's note: O'Reilly's Amazon Hacks recently released, so we asked author Paul Bausch to select some hacks from the book to highlight here. Find out how to search Amazon from any web page in IE, and how to create Amazon Associate links on your Movable Type weblog. And check back to this space next week for hacks on listing your Amazon items for sale on your own web site, and on creating a wireless wish list.
Create a file called AmazonSearch.html and add this code:
Save it in the c:\scripts\ directory.
Next you need to add some information to your Windows registry to let Internet Explorer know where to find AmazonSearch.html, and when exactly it should be executed. You could open up a registry editor and add values manually, but it's just as easy to put the information into a .reg file and add it by double-clicking. Create a new file called AmazonContext.reg and add the following code:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\[RETURN] Search Amazon] @="c:\\scripts\\AmazonSearch.html" "contexts"=dword:00000010
TIP: Backslashes, like those in filesystem paths, need to be escaped as
\\) in registry entry files.
Be sure to shut down all running copies of Internet Explorer. Once restarted, try browsing to any web page with text. Highlight any word and click your right mouse button. You should see the new entry as shown in Figure 1-18.
Figure 1-18. Search Amazon context entry
Click "Search Amazon" to open a new window with your search results for that term as shown in Figure 1-19.
Figure 1-19. Amazon Search Results window
Using external tools to integrate Amazon links into your web publishing system is helpful, but ease of use depends on features being built directly into the software you use to publish. That's the thinking behind Movable Type's plug-in system, and MTAmazon is a plug-in that can do much of the integration work for you.
Amazon.com product links, wish lists, and more can be automatically inserted into web sites managed by Movable Type thanks to MTAmazon, a Movable Type plug-in for Amazon Web Services.
Amazon Web Services (AWS) connect Amazon's databases with associate sites, showing search results, buttons to buy products, users' wish lists, and the contents of product categories without requiring the associate to make manual updates. For sites that use Movable Type, the MTAmazon plug-in provides a simple way to make use of AWS.
You can download MTAmazon and get instructions on installation and basic usage from the MTAmazon web site at http://mtamazon.sourceforge.net/.
Provide MTAmazon with a product ID, search string, or the list ID from a Wish List, Listmania! list, or product category, and it will retrieve a wealth of product information and provide Movable Type template tags with which to display it. If you know the ASIN for a product, you can insert a picture of it, the title, the price, and a button to add the item to the Amazon shopping cart.
<MTAmazon search="B00003CWT6" method="Asin" lastn="1"> <img src="<MTAmazonMediumImage>" align="left" border="0" hspace="5" /> <b><MTAmazonTitle></b><br /> <MTAmazonManufacturer> <p>Amazon Price: <b><MTAmazonSalePrice></b></p> <form method="POST" action="http://www.amazon.com/o/dt/assoc/handle-buy-box=<MTAmazonASIN>"> <input type="hidden" name="asin.<MTAmazonASIN>" value="1"> <input type="hidden" name="tag-value" value="<MTAmazonAssociateID>"> <input type="hidden" name="tag_value" value="<MTAmazonAssociateID>"> <input type="hidden" name="dev-tag-value" value="<MTAmazonDevToken>"> <input type="submit" name="submit.add-to-cart" value="Buy From [RETURN] Amazon.com"> </form></MTAmazon>
That's great, but it requires you to code the product's ASIN into your
templates. The plug-in wouldn't be very useful if you had to change your
templates every time you wanted to link to a different product. Fortunately
there's a way to use content from Movable Type in the MTAmazon code. For
instance, someone writing a book review in Movable Type can store the ISBN of
the book in the entry's keyword field and use that ISBN to automatically insert
a picture, price, and link to Amazon.com. Simply use the
<MTEntryKeywords> tag as your search attribute.
Movable Type typically won't let you use one MT tag as the attribute for another, but MTAmazon will let you fake it with a special tag format. If you use the tag name with square brackets around it, MTAmazon will evaluate the tag and use the output as the attribute value. For example, in the case of our book review:
<MTAmazon search="[MTEntryKeywords]" method="Asin" lastn="1">
MTAmazon can evaluate more complex expressions as well. This example will use the titles of the last five entries as the keywords for a book search:
<MTAmazon search="[MTEntries lastn="5"][MTEntryTitle] [/MTEntries]">
Movable Type tags are available only in templates, so to include links or images in your weblog entries, you'll need another plug-in. Process Tags (http://kalsey.com/2002/08/process_tags_plugin/) will let you use MTAmazon and other MT template tags in your entry bodies. With this plug-in, you can add associate links to books, movies, or games that you mention in your weblog.
<a <MTAmazon search="0425170349" mode="Asin"> href="<MTAmazonLink>"[RETURN] title="<MTAmazonTitle>"</MTAmazon>>this book</a>
One of the disadvantages to using Web Services to automatically insert associate links is that you may earn a lower commission on sales made through those links. Sales from AWS links earn only a 5 percent commission, while other links can earn up to 15 percent.
To take advantage of MTAmazon but still earn the higher commission, you'll need to replace the product links that MTAmazon generates with your own links. An Amazon associate URL is always in the format:
MTAmazon has tags for both the product's ASIN and your associate ID. You can use these to construct associate links that will earn you greater commissions:
— Adam Kalsey
Return to the Web DevCenter.
Copyright © 2009 O'Reilly Media, Inc.