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.

Imagine you run a site for photography enthusiasts. There are several subject areas and product categories that they may be interested in: books of photographs, magazines about photography, and digital cameras. Setting a single recommended product banner for books with photographs would be fine, but you may want to expand your product recommendations into those other subject areas to increase the chances that someone will find something they're interested in.

With a bit of scripting, you can set up some keywords and product areas, and randomly select them for each page visit.

63.1 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
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]
   width="468" height="60" border="0" alt="Shop at Amazon.com">


It's important to set up the list of keywords and product modes correctly (see the list in the form code of [Hack #64]). 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.

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.

63.2 Running the Hack

You can add this code to any ASP page, or make the code its own page and reference it from another file. For example, you could add the code to a file called amazon_banner.asp. Then, from another ASP file, use the server-side include method:

<!--#include file="amazon_banner.asp"-->

This keeps the banners easier to maintain, especially if they appear on several pages across your site. When you add or remove keywords, you'll only have to do it once.