Google AdSense for Zoom Search Engine

You can add Google AdSense to your custom Zoom Search Engine and provide ads which are relevant to the searches made on your web site.

Note: Wrensoft Zoom Search Engine is a software package which implements a custom search engine on your web site. It is a self-contained solution and requires no external service such as Google to provide search results. However, this article is for users who wish to add Google AdSense advertising to their website's search engine (powered by Zoom) to earn advertising commission.

This is a special feature with Google AdSense, and it requires you have an AdSense account with Google and also applied for active permission to use "AdSense Custom Search Ads".

More information can be found on Google's website here.

What this achieves

The main benefit from doing all this is that you can get ads which are relevant to the search query made by the end user on your website, using your own custom search engine.

Ordinary AdSense would return advertising that might be triggered by any keywords on your page, including for example, "Bob's Search Engine" that might be in the title, or other miscellaneous content on your search page unrelated to the subject searched by your end user.

To do this, you need to configure the options for your ads and tell Google what your end user searched for.

How to implement this

Please refer to the abovementioned official Google page for details on how to implement AdSense with configured options.

The following changes should be made on the "search_template.html" page.

As noted in the article, you need to load the JavaScript ads library by placing the following code inside the <head> tag.

<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript" charset="utf-8">
google.load('ads.search', '2');
</script>

Then you need to place the following code which initializes a "pageOptions" variable to pass on to Google ads.

It is here that we differ from Google's article, as we need to add a bit of JavaScript to retrieve the search query that is used by Zoom. This is the "zoom_query=" parameter that appears in the URL of the search page.

The blue text is the added code to the corresponding code block found in the Google article linked above.

<script type="text/javascript" charset="utf-8">

// This function will return the value of a GET parameter
function getParam(paramName)
{
  paramStr = document.location.search;
  if (paramStr == "")
    return "";
  // remove '?' in front of paramStr
  if (paramStr.charAt(0) == "?")
    paramStr = paramStr.substr(1);
  arg = (paramStr.split("&"));
  for (i=0; i < arg.length; i++) {
    arg_values = arg[i].split("=")
    if (unescape(arg_values[0]) == paramName)
    {
        if (paramName == "zoom_query")
          arg_values[1] = arg_values[1].replace(/[\+]/g, " ");

        if (self.decodeURIComponent)
          ret = decodeURIComponent(arg_values[1]);
        else // IE5.0 and older does not have decodeURI
          ret = unescape(arg_values[1]);
        return ret; 
    }
  }
  return "";
}

var pageOptions = {
  'pubId' : 'pub-xxxxxxxxxxxxxxxxx',
  'query' : getParam('zoom_query')
};

var adblock1 =
{
  'container' : 'adblock1',
  'number' : 3,
  'width' : 'auto',
  'lines' : 2,
  'fontFamily' : 'arial',
  'fontSizeTitle' : '14px',
  'fontSizeDescription' : '14px',
  'fontSizeDomainLink' : '14px'
};

var adblock2 = {
  'container' : 'adblock2',
  'number' : 4,
  'width' : '250px',
  'lines' : 3,
  'fontFamily' : 'arial',
  'fontSizeTitle' : '12px',
  'fontSizeDescription' : '12px',
  'fontSizeDomainLink' : '12px'
};

new google.ads.search.Ads(pageOptions, adblock1, adblock2);
</script>

The rest - Placing the ads on your page

The rest is as documented in the original Google article ("3. Choose where the ads should appear on your page").

For the sake of completeness, we reproduced the necessary HTML to place the ads on your page. The following two div tags are placed where you want your ads to appear.

<div id="adblock1"></div> <div id="adblock2"></div>

Return to the Zoom Search Engine Support page.