Serve Backup Ads
Use AdSense's built-in (and rather thoughtful) ability to serve ads from alternate URLs when there are no targeted ads to offer.
There's a time and place for public service announcements. You just might not think your web site is the place and certainly not if it happens more than occasionally. When you signed up for AdSense (while you're no doubt a good citizen who pays their public radio and television dues), your intent was to reap a revenue stream from all the hard work that you've put into your content.
Yet there are times when a new section of your site hasn't yet been noticed and indexed by Google, AdSense has nothing appropriately targeted in its inventory, or there's a temporary outage of some kind. The net result is that you'll be running public service ads for the Red Cross or the like rather than revenue-generating, targeted advertising. Google AdSense doesn't get paid and so doesn't pay you for click-throughs on public service advertisements.
Now, you can either simply be OK with this coming up every so oftenI know I amor you can make use of a backup system Google AdSense provides: alternate ad URLs.
Point your browser at Google AdSense (http://www.google.com/adsense) and click the Ad Settings tab at the top of the page. Then, scroll down until you see "Alternate ad URL or color," as shown in Figure 7-11.
Figure 7-11. Provide an alternate URL for ads when AdSense has only public service advertisements to offer your site
Google AdSense suggests (https://google.com/adsense/faq#basics10) four backup options:
Paste in the URL of an image somewhere on the Web, ad or not, static or dynamically generated. This can be an alternate image that you've created and are serving from your own site, one produced on-the-fly by another advertising service, or any other image that either has some revenue stream associated with it or simply tickles your fancy. For example, to serve up a static image named advert1.jpg residing on your web site, you'd provide a URL like http://www.example.com/images/advert1.jpg.
- Clickable image
Provide the URL of an HTML page somewhere out on the Web that contains only a snippet of markup for a hyperlinked image. For example, you might have a file on your site called adsense_alternate.html that contains the following line:
<a href="http://www.example.com/storefront/"><img src="http://www.example.com/ images/advert2.jpg border="0" /></a>
TIP: That's all the file should have in it, mind you; leave off all the opening
</body></html>bits and everything else you usually pack into your pages.
The URL you'd provide as an alternate would then be a pointer to that partial page, something like http://www.example.com/adsense_alternate.html.
- HTML color code
If you have nothing to display as an alternative and are dead set against running public service ads, blank out the space where the AdSense ad would have gone by, providing the hexadecimal HTML color code of your page's background or that particular bit of real estate. For example, if your page had a background color of
#160B35, a lovely dark blue that I use on my own site, you'd type that color code right into the "Alternate ad URL or color" field.
- Collapse your ad
Then again, there is a fifth alternative...
Amazon/Google Ad Replacement (AGAR; http://www.bestdealsdiscounts.com/agar; GNU Public License) is a Perl script that supplements your Google AdSense ads with product advertisement drawn from Amazon's Web Services (AWS; http://webservices.amazon.com) and Associates (http://associates.amazon.com) programs. Not only does it supplement AdSense, but it also mimics it in appearance, supports all the AdSense ad sizes, and allows you to customize your color scheme to match what you've chosen for AdSense.
TIP: For AGAR to be useful (and financially rewarding), you'll need to have signed up as an Amazon Associate (http://associates.amazon.com) through which you make money on purchases resulting from click-throughs on your site.
Download AGAR and get it running as a CGI script ["How to Run the Hacks" in the Preface]. There's not much at all you need to change in the script itself, save replacing the default Amazon Associates ID with your own:
my $associate_id = "insert your amazon associates id here";
WARNING If you're in the United Kingdom rather than the United States, you'll also want to change the locale in
my $locale = "us";to
$uk_associate_id = "coolstufftoown";to your U.K. Amazon Associates ID. If you're neither in the U.S. nor the U.K., there is some further adjustment necessary, but we leave that as an exercise for the reader.
Point your browser directly at the CGI script to test it out and you should see an ad banner, as shown in Figure 7-13, easily confused for an AdSense ad at first blush, but clearly linked to Amazon products.
Figure 7-13. An AGAR-generated AdSense-like Amazon banner ad
The product category is chosen at random by default (go ahead and
reload the page a few times to see this in action), but this can be
customized either by altering the settings baked into the script
itself or embedding settings into the
URL. For example, instead of just pointing at
This produces a 125 by 125 pixel ad drawing from
TIP: While the concept of
id, as expressed in the preceding URL is beyond the scope of this book, suffice it to say that you need to pass matching textual and numerical browse IDs. You'll find a detailed description of browse nodes and IDs in the Amazon Web Services documentation and a list of some of the text/number pairs in the AGAR code itselflook for
%browse_ids =. For an introduction to Amazon Web Services and all other things Amazon, pick up this book's cousin, Amazon Hacks (http://www.oreilly.com/catalog/amazonhks; O'Reilly) by Paul Bausch.
(If I may, I'd like to end with a pitch to at least consider letting the AdSense public service advertisements run. Sorry, I just couldn't help myself.)
Rael Dornfest is Founder and CEO of Portland, Oregon-based Values of n. Rael leads the Values of n charge with passion, unearthly creativity, and a repertoire of puns and jokes some of which are actually good. Prior to founding Values of n, he was O'Reilly's Chief Technical Officer, program chair for the O'Reilly Emerging Technology Conference (which he continues to chair), series editor of the bestselling Hacks book series, and instigator of O'Reilly's Rough Cuts early access program. He built Meerkat, the first web-based feed aggregator, was champion and co-author of the RSS 1.0 specification, and has written and contributed to six O'Reilly books. Rael's programmatic pride and joy is the nimble, open source blogging application Blosxom, the principles of which you'll find in the Values of n philosophy and embodied in Stikkit: Little yellow notes that think.
View catalog information for Google Hacks, 2nd Edition
Return to the O'Reilly Network.
Showing messages 1 through 1 of 1.
Curl and Google hacks
2007-08-13 04:01:02 rshiple [View]