Show Google AdSense to Visitors from Search Engines Only Using Drupal
Unbeknownst to people who visit my website directly, Just a Gwai Lo has served Google AdSense ads for some time now. Very early on I came to the conclusion that showing automatically-generated content-aware ads on personal sites was tacky, since those visiting directly were likely those who wanted to develop a personal relationship, no matter how loosely defined, with the author. That applies to the relationship I want to build with my readership as well: if they visit the site directly in a browser of subscribe to a feed, they shouldn't have something hawked at them.
People visiting through search engines, however, get no such treatment. They're likely people I don't know and, based on what people search for—and don't find on the site—don't want to have a relationship with. So anybody visiting in from one of the major search engines would see a Google AdSense ad, and over the years I've made enough to help fund some small vacations to the United States. (Since Google pays me in American dollars, it goes in my USD account, which I then withdraw for trips south of the border.) Nothing spectacular, and definitely not worth the amount of investment I put into the custom PHP script which looped through a list of domains returning TRUE
if one of those domains were Google, Windows Live Search (as it was known then), Yahoo! and some others. Now I use Drupal, the following contributed modules and a one-line conditional in the block display filter to show ads to people finding my site that way.
- AdSense, with the component modules "AdSense core" and "Managed ads" enabled.
- Search Engine Referer API, which returns
FALSE
if the referrer is not a search engine and an object (essentiallyTRUE
) if it is. - The following line of PHP in the "Page specific visibility settings" for the ad's block:
<?php if (module_exists('serapi')) { return serapi_get_search(); } ??>
I could have written a ternary operator, but I sought clarity in this case.
After my next payment, I'll disable this feature as part of an effort to simplify my Drupal install. This will cut down on the number of updates needed and ever so slightly decrease the load on the server. It's never been worth displaying them based on the time invested in this, though I can say the money plus experience with the advertising system in general did offset it a bit.