How to: Display adsense to search engines visitors only

It’s a fact: People who click on your ads are people comming from search engines, not regular readers. In order to avoid being “Smart Priced” by Google Adsense, you should definitely display ads to search engines visitors only. Here’s how to do it.

First, we have to create a function. paste the code below in your theme functions.php file. Create that file if it doesn't exists.

function scratch99_fromasearchengine(){
  $ref = $_SERVER['HTTP_REFERER'];
  $SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
  foreach ($SE as $source) {
    if (strpos($ref,$source)!==false) return true;
  }
  return false;
}

The $SE array is where you specify search engines. You can easily ad new search engines by adding new elements to the array.

Then, paste the following code anywhere on your template where you want your adsense ads to appear. They'll be displayed only to visitors comming from search engines results.

if (function_exists('scratch99_fromasearchengine')) {
  if (scratch99_fromasearchengine()) {
    INSERT YOUR CODE HERE
  }
}

Credits goes to Stephen Cronin for this awesome recipe!

40 Responses

Nov 19 2008 09:33

That is a fantastic way to limit your adsense ads to search engine viewers. I normally would use the “Who Sees Ads” Plugin, but if this works then I will ad this to my arsenal ASAP.

I did have a quick ‘Q’ for you though. Does the code above only block Adsense to users from Google, or is it all search engines? I am not that great at interpreting code, so any help would be rad!

Nov 19 2008 12:28

Note that a PHP-based solution won’t work properly if you use a caching solution, such as the WP-SuperCache plugin. Right?

As a suggestion for a future post, I’d like to see a Javascript solution to the same problem.

Thanks for the tip!

Nov 19 2008 13:04

@Luciano: I have never tried this recipe on one of my online blogs, so I can’t be sure about that but you seems pretty right on that one. A javascript solution is a good idea indeed, I’ll think about it!

Nov 19 2008 14:45

Interesting post! Chitika’s *Premium* ads ONLY show to US and Canadian search engine vistitors AND the targeting of the ads is based on the exact search engine query entered by the end user immediately before clicking to your site.

jeff at chitika dot com

Nov 20 2008 13:17

@Luciano WP Super Cache has support for custom caching, see the Other Notes
http://wordpress.org/extend/plugins/wp-super-cache/other_notes/

Donncha includes support for his No Adverts for Friends plug-in.
(Which also covers visitors from search engines too)

Nov 20 2008 19:43

Thanks for pointing it out, Lee!
I checked it and will try to implement in my blog soon.

If only there was a WP-recipes tutorial explaining it step-by-step! ;)

Nov 20 2008 21:40

@Luciano: You’re not the first to request more detailed tutorials. For the moment, WpRecipes is still young, but I should do that in a near future :)

Jan 08 2009 00:49

Can you share your revenue increase/ decrease after doing this trick?

Jan 08 2009 00:55

Also, will it show ads to reddit, digg , stumbleupon and other new users?

Jan 08 2009 01:14

@Vygantas: I’d like, but I have not implemented that trick on any of my blogs. You can add digg, reddit etc to the $se variable and visitors comming from theses sites will see ads.

Jan 08 2009 03:54

Wow, this is truly good and I think I have been “disliked” by Google for a while ^^ maybe this will fix our relation

Feb 19 2009 11:05

Why error on my blog?

Mar 24 2009 04:27

This is perfect, there is a plugin for this, but it’s useless, doesn’t work all the time, and this is just what I’ve been looking for, thank you!!

May 12 2009 05:16

Do I need to do anything to the adsense code before I replace ‘INSERT YOUR CODE HERE’ with it? I can’t get this to work the way it’s explained here. It seems like certain characters in the AdSense code (<, etc) are breaking the page.

May 18 2009 09:45

Thank you for your useful article.

Jun 07 2009 20:57

Great tip to prevent the blog from smartpricing. I will use this hack on my site and will post the results soon.

Jun 11 2009 05:04

Is there a way not to show adverts to visitors from few websites only and display to everybody else? I would love to have that code.

I would appreciate the help very much. Ready to pay too.

Jun 25 2009 00:22

Thanks. Can you give us an example of the code with the search engines included in this array? I’m unclear on how to specify search engines in the $SE array. Thanks.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required
Blog And Make Cash