Monthly Archives: March 2011

WordPress – Display AdSense Ads to Search Engines Visitors Only

It’s a known fact that regular visitors don’t click on ads. Those who do click on ads are, 90% of the time, visitors coming from search engines.

Another problem is Google’s “smart pricing.” Being smart priced means that your click-through rate (CTR) is low and the money you earn per click is divided by between 2 and 10. For example, if a click would normally earn you $1.00, with smart pricing it could earn you as little as $0.10. Painful, isn’t it? Happily, this solution displays your AdSense ads to search engine visitors only, which means more clicks and a higher CTR.

The solution.

Open the functions.php file in your theme.
Paste the following code in it:

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;

}

Once done, paste the following code anywhere in your template where you want your AdSense ads to appear. They’ll be displayed only to visitors coming from search engine results:

if (function_exists('scratch99_fromasearchengine')) {

  if (scratch99_fromasearchengine()) {

    INSERT YOUR CODE HERE

  }

}

Code explanation. This hack starts with the creation of a function called scratch99_fromasearchengine(). This function contains a $SE array variable in which you can specify search engines. You can easily add new search engines by adding new elements to the array.

The scratch99_fromasearchengine() then returns true if the visitor comes from one of the search engines containing the $SE array variable.

YUI – YUI Event

http://developer.yahoo.com/yui/event/

YAHOO.util.Event.addListener(el, sType, fn, obj, overrideContext)

el: id, or a collection of ids
sType: the type of event to append (such as “click” http://www.quirksmode.org/dom/events/)
fn: the method the event invokes
obj: an arbitrary object that will be passed as a parameter to the handler
overrideContect: if true, the obj passed in becomes the execution context of the listener; if an object, this object becomes the execution context

YAHOO.util.Subscriber( fn , obj , overrideContext )

fn: the function to execute
obj: an object to be passed along when the event fires
overrideContext: If true, the obj passed in becomes the execution context of the listener

There are 2 main types of event subscriptions:

//DragDrop
var dd = new YAHOO.util.DD('dd');
dd.on('dragEvent', function() { });

//Panel
var panel = new YAHOO.widget.Panel('panel');
panel.renderEvent.subscribe(function() {});

//Calendar
var cal = new YAHOO.widget.Calendar('cal');
cal.selectEvent.subscribe(function() {});

//Editor
var editor = new YAHOO.widget.Editor('editor', {});
editor.on('afterRender', function() {});