O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Amazon Hacks
By Paul Bausch
August 2003
More Info

HACK
#63
Rotate Through Several Keyword Banners on Your Site
Keyword banners provide some rotation as people visit your site, but to do cross-promotion with several keywords across categories, you'll have to script a rotation solution
The Code
[Discuss (4) | Link to this hack]

The Code

The following code can be added to any ASP page:

<%
'Add Keywords separated by commas
strKeywords = "insert comma-separated list of keywords"

'Add Modes separated by commas
'Potential values: books, magazines, music, classical-music, 
'  vhs, dvd, toys, baby, videogames, electronics, software, 
'  tools, garden, kitchen, photo, wireless-phones
strModes = "insert comma-separated list of product modes"

'Turn lists into arrays
arKeywords = Split(strKeywords,",")
arModes = Split(strModes,",")
intTotalKeywords = UBound(arKeywords)

'Choose a random number
Randomize
intRndNumber = Int((intTotalKeywords + 1) * Rnd + 1) - 1

'Set variables to the chosen random point in the array
strKeyword = arKeywords(intRndNumber)
strMode = arModes(intRndNumber)

'Make sure the keyword string is URL-safe
strKeyword = Server.URLEncode(strKeyword)
%>

<iframe marginwidth="0" marginheight="0" width="468" height="60" 
   scrolling="no" frameborder="0" 
src="http://rcm.amazon.com/e/cm?t=onfocus&l=st1&search=<%= strKeyword %>[RETURN]
&mode=<%= strMode %>&p=13&o=1&f=ifr">

<a href="http://www.amazon.com/exec/obidos/redirect-home/">
   <img src="http://g-images.amazon.com/images/G/01/associates/books2000/[RETURN]
clock468x60a3.gif" 
   width="468" height="60" border="0" alt="Shop at Amazon.com">
</a>

</iframe>

It's important to set up the list of keywords and product modes correctly (see the list in the form code of ). Extending the photography site example, here's how some banners could be set up:

'Add Keywords separated by commas
strKeywords = "photographs,photography,photography,digital photography,[RETURN]
digital cameras"

'Add Modes separated by commas
strModes = "books,books,magazines,books,electronics"

Notice that the positions of the keywords and the modes match. Though the second and third entries in the keyword string are both photography, the second and third positions in the modes string are different: books and magazines. When the random entry selected is 3, the banner will show magazines that match the keyword photography; when it is 2, the banner will show books that match the keyword photography.

TIP

If you already have keywords in <meta> tags for a given page on your site, you can use those as your keyword string and add appropriate product categories.


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.