Dynamic Amazon Ads?
Posted on July 24, 2007
2 Comments
Wouldn't it be neat to have Amazon ads, like I do in my sidebar, show books related to the current post being viewed? For some odd reason, that idea popped into my head earlier this evening and initiated a quest. A quest that got me close, but ultimately, left me a bit disappointed. Follow along to see what I did. I'm hoping someone can build on this and help me figure out where I went south.
The idea originally came to me as I was looking over the Amazon Affiliate code for suggested book. I noticed one of the querystring parameters looks like:
search=security%20hacking
(that %20 represents a space)
As you might surmise, this tells Amazon what sorts of books to show. In this case, that would be books related to security and hacking.
Well, I run the Ultimate Tag Warrior plugin, so I have tags all over the place. I figured it might be simple to whip something up that would feed the right tags into the Amazon thing for each page. Thus showing books on that topic.
First, using the wonders of WordPress Conditional Tags, I modified my sidebar to only show the Amazon Ad on single post view pages.
-
<?php if (is_single()) { ?>
-
<!-- Amazon code goes here -->
-
<?php } ?>
Now, the part that took some extra messing around. I need to convince UTW to give me just a plain old list of tags. Not links, and minimal formatting -- oh, and seperated by "%20" instead of spaces.
To do that, I had to learn about custom format strings. This is the end result:
-
<?php
-
'default'=>'%tagdisplay%%20',
-
'last'=>'%tagdisplay%');
-
UTW_ShowTagsForCurrentPost("custom", $format);
-
?>
Doesn't look like much, does it? Took me almost 45 minutes to figure out though!
It works great, if the tags for an article are "security, backups, operations", that little bit of code spits out
security%20backups%20operations
Finally, I copied the Amazon code and replaced search=security%20hacking with the code above. Loaded a few pages and, in viewing source, I could see that my tags were showing up in the right place.
However, the books that were being suggested were definitely out of left field! Apparently, Amazon doesn't work quite as dynamically as this? Or maybe there's a different way to go about it. I guess I have more research to do.
If anyone can take this to the next level (you know, the level where it actually works?) please have at it -- and share when you're done!
[Updated] Oh snap! This would make them contextual ads, wouldn't it? That would cause problems with the main contextual ad providers... if you're using them, you probably don't want to do this.
Tags: advertising, amazon, programming, ultimate-tag-warrior, WordPress
Possibly Related Posts
Comments
2 Responses to “Dynamic Amazon Ads?”
Leave a Reply



Thats a pretty good idea! I do not show amazon ads myself, but I used to and they didn’t generate much income. If they were more targetted to the content, and showed specific books it would generate so much more money.
Maybe one day amazon does this. Hopefully, and I will start using them again.
To bad one can’t have everything… but anyway, good idea
I think Amazon has a lot to do, like cookie tracking for 30 days for referrals…
Regards, Moxy.