Conditional Adsense — In Which I Hop On The Bandwagon

I’ve spent a lot of words over the years railing against the infiltration of advertising into our weblog world, and enjoyed that righteous glow that comes from standing up for a principle, regardless of how well- (or poorly-) founded the thinking on that principle be.

Here comes the ‘but’.

But I’ve rethought things a bit, in no small part after reading the essay Matt Haughey wrote here.

Imagine that — ads that actually make a page more valuable to readers, not just the site owners. Random people searching for information are much more likely to click on those related text ads if the ads help them find what they are looking for. Compare that to a regular visitor that comes to your site dozens of times a week: How often are they going to click on any ads? How quickly will they learn to visually filter out the ads entirely from the experience? Superfans develop banner blindness extremely quickly.

What I realized when I looked at my Google Analytics reports was that the majority of ad clicks are coming from these one-time visitors looking for information. I do it myself when searching, especially if it’s for a product of some type. I’ll search, dive into the results, and if the top 5 don’t have what I’m looking for, I’m very likely to click on related ads to see if that’s what I’m looking for. New visitors to a site love to click on anything that brings them closer to their goal, and often times that’s an ad. This, in essence, is the entire business model of per-click advertising.

I’ve always been annoyed by advertising in general, on the web or anywhere else. A lot of my ire in recent years has been directed at Adsense, and that has been mostly because of its ubiquity, I suppose. I’ve always been unshakeable in my conviction that advertising is about the enrichment of the marketing company and the manufacturer of the product or provider of the service being advertised, and about the deliberate manipulation of the people being advertised to, typically to their detriment. Defenders of the Ad often suggest that we, the Consumers, wouldn’t be able to find out about all these products and services created and sold to improve out lives. Well, I suppose there were times when I discovered something I simply couldn’t live without through advertising, but I can’t remember it ever happening. Documentaries like the excellent four part ‘Century of the Self’ did nothing to dissuade me from this, and hammered home for me the ways in which I thought that advertising had interpenetrated and cheapened our modern cultures.

I still think that I’m right about all that.

But Matt triggered some new thinking for me, new thinking that I suppose I’d been tenderized for by building one of my other sites and putting Adsense on it out the gate — the rarely-updated OutsideinKorea. From the get-go, I assumed that it would be a site that people would mostly arrive at from search engines, and not be a regularly-updated, regularly-visited-by-readers webloggy kind of project. And so I put up the ads (for which I’ve still not made enough to get a single check, more than a year later, but I’ve really let it languish, so the fault is nobody’s but my own, from a revenue point of view).

But I hadn’t really followed that thinking through, and what Matt had to say helped me do that.

Two ideas here: that when we’re talking about weblogs and advertising, that an awful lot of people who land on the site (by far the largest ongoing slice of visitors — bar the Digging and Slashdotting et al last year, which was a transient traffic rogue wave) come from search engines. From Google itself, mostly. These people are looking for something, something they’re hoping they might find here. Probably not a product. More likely some piece of information.

It’s possible, I hope, that they find it on the individual archive page they land on here at the ‘bottle, but they might not. If not, then they’ll go on to find it elsewhere, and it’s entirely possible that they might find it following a contextual ad from Adsense.

The ads might actually help them, as well as me, if they click on them. They might actually serve some useful purpose to both parties involved, something I’d never really been able to get behind as a justification for advertisements for the latest variation of Coca Cola, or the newest erectile-dysfunction chemical.

But I didn’t want ads plastered all over the place creating visual clutter for people who actually do regularly visit, who arrive from other weblogs or comments I make elsewhere, or from RSS feedreaders when I make an update. People who are here for the wonderchickeny goodness, not the sifting-through-sum-total-of-human-information.

The solution, of course, as Matt suggested, was to display ads only if people come from one of the traffic firehoses (Digg and Slashdot and Wikipedia and Stumbleupon and the search engines), and not display them if people come from their bookmarks or another weblog or pretty much anywhere else.

I don’t know why I never thought of it before.

So here’s what I’ve done to display ads to visitors conditionally, based on the referrer, using Movable Type. Feel free to borrow and use this yourself — it’s not complicated, and all the reading I’ve done has indicated that it does not in any way violate the Adsense terms of service. There may, of course, be better ways to do it. My coding skills are, to put it kindly, somewhat haphazard.

1) I created a couple of modules in Movable Type, one for each Adsense format I wanted to display. At the moment, I have two modules named module-banner and module-leaderboard Each holds the appropriate Adsense-generated code for that style of ad block, wrapped in a div and a bit of php code to check where the visitor has come from.

The modules look like this. I wrap the whole thing in a div so I can style it, if I want. (You could, of course, customize the referrer list anyway you liked.)

<div class="topbanner">
if (isset($_SERVER['HTTP_REFERER']) && preg_match("/^https?:\/\/[0-9a-z]*\.?(google|yahoo| stumbleupon|digg| wikipedia|slashdot|lycos|altavista)\..+\/.*$/i", $_SERVER['HTTP_REFERER']))  {
echo <<<END

2) I include the modules in any index template I wish to conditionally display Adsense ads like so:

<$MTInclude module="module-banner"$>


<$MTInclude module="module-leaderboard"$>

depending on which of the two ad styles I want to include.

I may make other module variations in future, of course. At the moment, I’m only displaying ads in Individual Archive Templates.

3) I long ago switched all of my extensions over to .php to use some other php inclusions, so that just worked for me. You may need to do make a filetype change (it’s in the settings area in Movable Type) (and possible .htaccess edit — I fly this stuff by the seat of my pants!) .

And that’s it. Now searchers/visitors from the sites I nominate get ads that may help them find what they’re looking for, if it isn’t here, and regular blog visitors who come from pretty much anywhere else don’t. You can test this out by hitting this Google search, then following the first hit back to here. You’ll see ads. Paste the URL directly in to the address bar (for example) and you won’t. Magic!

I probably won’t make much money from this, either. But given the 10,000+ visits that make up an average month at the bottle, more than half of which arrive from search engines, perhaps I’ll make enough for a beer or two each month, and do it without (I hope) annoying any of my loyal readers who’ve stuck with me for all these years.

Share and enjoy.

[Update: Thanks to the most excellent skills of my friends and neighbours, I've made a few changes to smarten up the referrer checking code. Major thanks to Ed Eliot, who was kind enough to whip up something better and explain what the Evil Regex was doing. I've updated the code for the MT modules above accordingly -- my implementation is very slightly different from his, which ought to work anywhere PHP is spoken, of course.]

Share a drink

10 thoughts on “Conditional Adsense — In Which I Hop On The Bandwagon

  1. ereg is probably the most expensive way PHP has to determine if one string can be found in another string – strpos($referer, “”) !== false should be much cheaper (and, since “.” isn’t a special character like it is in regular expressions, you won’t match on

  2. Wow, that was fast!
    So you reckon replacing (for example)
    ereg ( “”, $referer ) ||
    strpos($referer, “”) !== false ||
    would be the way to go?
    Let me know, and if that’s what you mean, I’ll update the code, try it out, and update the post.
    (Thanks for the tip, BTW, Phil. Like I said, code ain’t my fort&eacute’…)

  3. Kinda sorta – you’re only trapping, whereas I come from and other will come from the country-specific Google domain.
    You may need to go back to the regexp variant!

  4. For what you’re doing, yeah, strpos() is what you probably want. If you want to match actual patterns, e.g. google.(anything), that’s what regular expressions are good for. But that’s probably not worth the time figuring it out.

  5. Advertising is a public service? Just goes to show you how far someone can go to rationalize profit.
    I’d say 90% of my hits are from random searches; past searches are probably also responsible for at least half of the remaining 10% that end up reading me for some duration before I bore them to tears. Given that more people have unsubscribed/quit reading my blog than start reading my blog in any given month, I figure the best public service I could offer would be to remove my entries from the web, say within 30 days, so that searchers won’t be decieved by them when they are looking for something else.
    Better still, since a very small percentage actually find what they’re looking for at my site, why run one at all? That’s it. I quit.
    Wait. I forgot that I actually run my site primarily for my own benefit. That changes everything. Nevermind.

  6. Advertising is a public service? Just goes to show you how far someone can go to rationalize profit.
    Heh. I wondered when someone would call me on my shit, Jeff.
    You’re absolutely right, of course — it is a rationalization, and possibly a weak one. Nonetheless, though, I don’t see a downside to doing this for *anyone* involved, other than perhaps the stain on my immortal soul.
    But I made a massive, like, dollar fifty yesterday, and I’m MAD WITH THE RICHES and I’m not turning back now, suckers!

  7. I’ve still not made enough to get a single check, more than a year later
    Stav, adsense is decidely crap money which is why the goalposts of rationalisation get moved for many sites, and they end up jumping in a bit more full on. I do think that people are generally more accepting of some mild advertising these days and I suspect Matt’s model for superusers/adverts is most useful when applied to sites the size of Mefi.
    There are a fair few people who, when they visit blogs they like run by individuals not in the A-List, are happy to click on the ads on their way out as a form of tipping. If the ads aren’t toooo intrusive, they won’t even notice them at all — that’s the way we all surf. So restricting ad-serving just to search/digg types when you are a modest fish in the pool isn’t necessarily providing a core readership with any great favours. Some of them might appreciate it sure, but most people either tip or are oblivious and will keep coming back in either respect.
    Mefi is a community site so the superusers actually make the site contents — in such a case it makes sense to reduce their clutter. But when it’s a personal site and your own sweat going in, it’s possibly a false conclusion to think that no ads for everyone save for goolge et al is in fact having any real effect. Maybe I’m reading it wrong but when ads aren’t intrusive, the vast majority of people will not judge you or the site harshly.
    So in terms of revenue, what you do on a personal site when you don’t serve ads is restrict a possibly continuous tipping stream. That’s my take anyway.
    And with the Korea site, the little ad block there will never get money. People have to first choose one of the categories and THEN click the advertised site in the list that’s served to them. So it requires 2 clicks to register for money. You would, imo, be better off putting just a small ad box that serves the ad directly. I don’t suppose it will make any huge difference (but I generally disagree with Matt that people choose ads to click on when they come to a page looking for info) but I’m certain it will increase conversions a tad.
    Yes, I left a tip!

  8. Movable Type on The Rebound

    I’m really pleased to see Sixapart’s new direction with Movable Type. I haven’t really seen that much talk about it around the blogs (which I only keep half an eye on these days, mostly because I’m busy on my own…

Comments are closed.