Using AdSense Backup Ads

After sucessfully using AdSense for a while, and seeing great results, I noticed that the number of "Unmatched Ad Requests" was climbing. What this meant was that my pages were being displayed and no ad was being served up by AdSense resulting in a blank area on the pages. The blank area wasn't the problem, it doesn't affect the display of the content, but the thought of an unused resource seemed wasteful: some ad could be displayed that might bring in some additional revenue! Thankfully, AdSense has the ability to display an ad another URL.

To know if you are getting "Unmatched Ad Requests", go to the Performance Report section and pick a report such as Targeting Types and it should list the number of "Unmatched Ad Requests". These are missed chances for revenue. So now you know that ads are not being displayed, but what can be done to display an ad?

Unmatched requests

From the help in AdSense, there are hints that you can give AdSense a URL to pull another HTML page to serve up ads. At first blush, this might look like you're stuck with one ad. If you are creative, you could build a small HTML page to display a table of ads to fit into 728x90 or whatever size you need to fill, but you would still be fairly limited with straight HTML. If you have a scripting language in use, then the options have widened considerably, for the request for an HTML page could be interspersed by a script to dynamically serve ads when AdSense won't fill the space (for a scripting language such as PHP to also parse HTML files, look into the .htaccess file. Hosts may vary, but it's typically a section like <FilesMatch "\.(html)$">Options +ExecCGI</FilesMatch>).

Before creating any new HTML page, it is necessary to have something to serve up. To have a new ad or ads, it will be necessary sign up with another ad network or affiliate marketing service. Sign up, create ads and get the code for their ads handy as it will be used in the new "HTML page". Search for Affiliate Marketing or Ad Network to find a service who will accept your site and has relevant ads or products to your audience.

Now that you have the code for the new ad or ads, it's time to create the new page that AdSense will invoke when AdSense does not have an ad to display. This file must have a .html extension, and will look like any other HTML file. The output of your HTML file will be displayed in the location of the original AdSense ad.

With PHP, and assuming that the server is configured to also parse html files, the code could look something like:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<?php 
switch (rand(0,2))
{
  case 0: // Affiliate Marketing link #1
    echo "<script type=\"text/javascript\" " + 
    "src=\"http://www.someaffiliatemarketingcompany.com/link.php" +
    "?ml=99999&p=999999amp;pw=9999999\"></script>";
    break;
  case 1: // Another Marketing link #2
    echo "<script type=\"text/javascript\" " +
    "src=\"http://www.someaffiliatemarketingcompany.com/link.php" +
    "?ml=888888&p=8888888&pw=999999\"></script>";
    break;
  case 2:
    echo "<!-- Another Ad Network - ad code starts -->";
    echo "<span id=\"show_ads_08742faabbcc99d\"></span>";
    echo "<script language=\"javascript\" type=\"text/javascript\" "
    "src=\"http://www.altadnetwork.com/show-ads.js\"></script>";
    echo "<script language=\"javascript\">";40daa6a2112=ads_f00ba4;";
    echo "blah blah blah, a bunch more code";
    echo "</script>";
    echo "<!-- Another Ad Network - ad code  ends -->";
    break;
}	
?>
</body>
</html>

This is a handy way to also test your page, as it is possible to post this file to the site and invoke it to see the ad(s). Notice that the ads will be "rotated", but randomly. In the example HTML above, there are three possible ads to display (all the URLs and code is only mocked up and won't really display anything). These three ads are from the alternate ad networks. Also note that it is necessary to escape the " using \" to match the original code when emitted by the PHP parser.

The final step, after the new page has been posted to the site, is to return to AdSense and edit the original ad. Within AdSense, select the ad you have developed the alternate ad HTML (and make one alternate ad HTML file for each size ad on your site), go down to the Backup Ads and open that section. The Select "Show other ads from another URL" and paste the fully qualified URL to the new ad page. Now AdSense should invoke your alternate ad page, and the sites' ad inventory isn't being wasted.