Conditionally showing Google Ads - Jon Galloway

Conditionally showing Google Ads

Google Ads!

Summary

Consider hiding ads on your site depending on how the user got there.

Why?

A friend of mine recently experienced an unexpected surge in traffic to his site. He's been subject to a rampage of Digg-ers ever since then, scrambling to cut his image and RSS bandwidth.

He's got some philosophical issues with showing ads on his site. I understand, but I think it makes sense to segment your users into two groups:

  • Preferred users - These folks came directly to your site and will see no or minimal ads. Visitors who arrived via a bookmark or RSS feed link are unlikely to click on ads anyway.
  • Walk-in users - these folks came to your site via search results or social recommendation sites like Digg, and can deal with a few ads. Visitors who found your site via search are looking for something and, heck, it just might come up in a contextual ad. Visitors who came via social bookmarking sites (on average) are a different class of user - they chew up bandwidth, spend a few seconds (3.6 seconds on average, to be precise) on your page, post an inane comment, and move on. They can deal with some ads to offset the trouble they're causing. Sure, Digg users aren't going to click on ads, but at least they'll contribute to the CPM ad count.

How to do it

I first read about this idea when David Brunelle added conditional advertising on his blog. It's a simple enough concept - check the referrer, and if they're in a list of domains, they get the ads. Our friends and co-workers and Moms who bookmark our pages don't get the ads. His sample is in PHP.

The simplest solution seems to be the way Juan Julián Merelo came up with - just modify the Google AdSense Javascript so it only shows the ads for domains in a list. I modified his script a bit and came up with the following:

<script type="text/javascript"><!-- google_ad_client = "pub-4855992354458847"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; //--></script> <script type='text/javascript'> if ( (document.referrer.indexOf( 'digg' ) > 1) || (document.referrer.indexOf( 'slashdot' ) > 1) || (document.referrer.indexOf( 'reddit' ) > 1) || (document.referrer.indexOf( 'google' ) > 1) || (document.referrer.indexOf( 'msn' ) > 1) || (document.referrer.indexOf( 'yahoo' ) > 1)) { document.write("<sc"+"ript type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></scr"+"ipt>"); } </script>

My friend - the one who got all the Digg traffic and got me thinking about all this stuff - has a bizarre condition that makes him overcomplicate nearly everything, so his blog is running his blog on MovableType. You may think it's a lame blogging platform, but you'll you may change your mind when you hear that it can run scripts in a state of the art language known as PERL. I didn't bother translating it to different server side languages because the Javascript sample is universal, but here's a sample PERL script in case you're a total backwards goofball with a popular MoveableType blog and you decide to conditionally show ads:

if (($ENV{'HTTP_REFERER'}) && ($ENV{'HTTP_REFERER'} =~ /^http:\/\/(www\.)*(digg\.com|reddit\.com|slashdot\.org|del\.icio\.us)/)) { # referrer came from the domain list that gets ads <script type="text/javascript"><!-- google_ad_client = "pub-4855992354458847"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> }

Google Ads!

Do as I say, not as I do

I'm not doing this on my blog. Since my is hosted at weblogs.asp.net, I don't have the control to put ads in with the content, just down in sidebar. See? No, down there. Yeah. Not worth the trouble to hide them. The ads in this post are fakes, in case your highly trained eyes just filtered them out. Out of curiosity, Did anyone not notice?

Google Ads!

Published Thursday, March 8, 2007 1:25 PM by Jon Galloway

Comments

# re: Conditionally showing Google Ads

Duuude, I use google reader so I'm still subjected to ads using this approach. Bummer!

;)

Thursday, March 8, 2007 5:55 PM by Haacked

# re: Conditionally showing Google Ads

I have to admit, I saw the ads but didn't read a single word of them until you pointed them out. It is like my mind recognized the pattern and immedately skipped them.

Thursday, March 8, 2007 6:35 PM by Jonathan Allen

# re: Conditionally showing Google Ads

Sounds pretty cool! Could you please guide me if modifying Google AdSense code is legal or illegal?

Thanks!

Saturday, March 17, 2007 3:04 AM by Avinash

# re: Conditionally showing Google Ads

Didn't notice the ads.  Had no conscious idea that the page even had ads until i started reading the comments down here and was like wtf, there were ads?

Monkeys Online.  Very cool.

Saturday, October 6, 2007 1:29 PM by will
Thanks for sharing your feedback! If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish - or longer if the blogger is moderating comments.