Hack 85. Serve Backup Ads

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

backup options: Image
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_alternatel that contains the
following line: <a href="http://www.example.com/storefront/"><img src="/image/library/english/10054_advert2.jpg border="0" /></a>
|
a pointer to that partial page, something like
http://www.example.com/adsense_alternatel.
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
Google provides an HTML file you can download to and serve from your
own web site that calls a bit of JavaScript to collapse your ad so
that it doesn't show in the event
you'd otherwise have seen a public service ad. For
instructions and a link to download the file, visit #basics13.
Whichever you choose, when you click the "Update
code" button, a smidgeon of JavaScript (the third
line in Figure 7-12) will be added to the AdSense
code that you paste into your web page. This additional line provides
all AdSense needs to serve up your alternate ad choice when it has no
targeted ad to run on your site.
Figure 7-12. An alternate ad URL embedded in Google AdSense JavaScript code

(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.
|
["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";
|
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

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 agar.cgi
URL. For example, instead of just pointing at
agar.cgi, try
agar.cgi??input_mode=kitchen&input_id=491864&ad_format=125x125_as.
This produces a 125 by 125 pixel ad drawing from
Amazon's "kitchen"
category.
|
consider letting the AdSense public service advertisements run.
Sorry, I
just couldn't help myself.)