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.

<head>

<script type="text/javascript" charset="utf-8">
  (function(G,o,O,g,L,e){G[g]=G[g]||function(){(G[g]['q']=G[g]['q']||[]).push(
  arguments)},G[g]['t']=1*new Date;L=o.createElement(O),e=o.getElementsByTagName(
  O)[0];L.async=1;L.src='//www.google.com/adsense/search/async-ads.js';
  e.parentNode.insertBefore(L,e)})(window,document,'script','_googCsa');
</script>						
					

</head>

Next, you need to place the following code within the <body> tag.

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.

<body>

<div id="adcontainer1"></div>
<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 "";
}

// Replace pub-xxxxxxxxxxxxxxxxx below with your pubId from your Google AdSense account information

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

var adblock1 = {
  'container' : 'adcontainer1',
  'width' : 700,
};

var adblock2 = {
  'container' : 'adcontainer2',
  'width' : 700,
};

_googCsa('ads', pageOptions, adblock1, adblock2);
</script>


<div id="adcontainer2"></div>

</body>

The rest - Placing the ads on your page

The rest is as documented in the original Google article.

Note that the two div tags (adcontainer1 and adcontainer2) will be where your ads will appear on the page. So place them as you wish them to appear.

Return to the Zoom Search Engine Support page.