terminator Before I tell you how to reduce AdSense impressions while improving the click-through rate (CTR) at the same time, I have to admit I dropped the ball on this one. Back in July, I published "Reducing AdSense Impressions from Robots", and then later inserted an update message saying I wasn't doing it that way. I meant to do a follow-up after testing, but I got sidetracked by real-world events.

These techniques require you to insert code which will set a condition. A condition of 0 will allow an AdSense block to be displayed while a condition of 1 will prevent it.


Blog Software Loops

The WordPress platform uses a loop to display posts and I'm sure other platforms do too. Any conditional code should be used before the loop starts. Unfortunately, in some cases it can't be helped. Categories and tags have to be retrieved from within the loop for WordPress.

The first two batches of code can be used before the loop.

The MSN/Live Robots

Certain MSN/Live Robots are operating with JavaScript enabled and are therefore causing needless AdSense impressions. It won't do you any good to try to block the log entries or block the robots, but you want to prevent them from causing the unnecessary impressions. This will create the prevention condition:

$skipadsense = 0;
$searchref = $_SERVER['HTTP_REFERER'];
$live = array('FORM=LVSP', 'FORM=LIVSOP', 'FORM=QBHP', );
foreach ($live as $livesearch) {
    if (stripos($searchref, $livesearch)) {
        $skipadsense = 1;
        break;
    }
}

Search Terms

Those of us with experience know that bloggers and other types of visitors will never click on AdSense ads. If they're searching for something that you know won't result in a click, you want to set a prevention condition. You may laugh, but this applies to niche sites as well.

This is the code I use for the terms I've spotted. I've repeated the first line from the previous code block for the sake of completeness:

$skipadsense = 0;
$request_uri = $_SERVER['REQUEST_URI'];
$noads = array('site:www.untwistedvortex.com', 'site:untwistedvortex.com', 'powered by wordpress', 'leave a comment', 'commentluv', 'keywordluv', 'dofollow', 'do follow', 'nofollow', 'no follow', 'blog',);
foreach ($noads as $noad) {
    $pos = stripos($request_uri,$noad);
    if ($pos !== false) {
        $skipadsense = 1;
        break;
    }
}

The Categories and Tags Arrays

You can set this up either before or right after the loop the starts (if you have a loop). In WordPress, the loop starts with something like "if (have_posts()) : while (have_posts()) : the_post();. You can combine two arrays into one, if the categories and tags are unique enough. I suggest using the slugs for the categories and tags instead of the names in case you edit the names later. This is a sample:

// categories:
$noads1 = array('blogging', 'blog-reviews', 'website-reviews',);
// tags:
$noads2 = array('reviews', 'seo', 'wordpress',);

The Categories and Tags Code

In WordPress, these must come after the loop:

foreach (get_the_category() as $category) {
    if (in_array($category->category_nicename,$noads1)) $skipadsense = 1;
}
$posttags = get_the_tags(); if ($posttags) {
    foreach($posttags as $tag) {
        if (in_array($tag->slug,$noads2)) $skipadsense = 1;
    }
}

The reason you have to check for post tags and not categories is because WordPress requires at least one category (such as "Uncategorized") while it doesn't require any tags.

If you have a post that doesn't fall within a particular category, but it shouldn't show AdSense, you can either use an existing tag or you can create your own to insert. I use "noads" for that purpose, just in case I forgot to include a particular category or tag.

Before and After the AdSense Code or Plugin Function

Whether you put the raw AdSense block on your page, calling a plugin or within a plugin, the principle is the same. I call a plugin. Anyway, if you get a condition of 1 out of any of the above code, this code will prevent the AdSense block from appearing.

if (!$skipadsense) {
<!–insert adsense block or plugin code–>
}

Finishing Up

Remember to watch your PHP opening and closing tags and everything should work fine. You can use it on standard template pages that show posts (i.e. "index.php", "page.php", "archive.php", etc.), but you can't use it on template pages called unless you have AdSense blocks on those pages (i.e. "header.php", "sidebar.php", "footer.php", etc.). If you use Blogger, you may want to read a different article to learn how to control who gets ads.

After I inserted this code on my "single.php" template page, my CTR doubled virtually overnight.

Disclaimer: Your mileage may vary. Slippery when wet. Objects are closer than they appear. If there are any errors in the documentation, blame someone else.