Publishers using AdSense for search now have the option to open search results within their own websites. By adding an additional set of search results code to your page, you can display Google search results framed within your own site. This new option will help you blend AdSense for search into your site even further. You'll also have the added advantage of keeping users on your site while still offering them the useful information available through Google search.

The new search results option is available during the AdSense Setup. Once you've chosen AdSense for search as your product and are customizing your search box and results, just choose the box marked Open results within my own site. Or, follow the instructions in our Help Center entry: How do I implement search results on my page?

Here is the link.

Question: How do I do this on Drupal?

Comments

Cromicon’s picture

Go through the google setup and create a page on your site using the full html filter and insert the code they give you. Your code may differ to mine dependant on options you chose.

<!-- Google Search Result Snippet Begins -->
<div id="googleSearchUnitIframe"></div>

<script type="text/javascript">
   var googleSearchIframeName = 'googleSearchUnitIframe';
   var googleSearchFrameWidth = 650;
   var googleSearchFrameHeight = 1300;
   var googleSearchFrameborder = 0 ;
</script>
<script type="text/javascript"
         src="http://www.google.com/afsonline/show_afs_search.js">
</script>
<!-- Google Search Result Snippet Ends -->

Put that newly created pages URL in the field where they ask you what page the results should be shown on.

Next, you need to replace the search box on your site with the one they provide you with. How you do this depends on the theme you are using. I'm using Fancy that uses the PHPTemplate engine. The code I need to replace is here:

    <td id="menu">
	<?php if ($search_box) { ?><form action="<?php print $search_url ?>" method="post">
        <div id="search">
          <input class="form-text" type="text" size="15" value="" name="edit[keys]" alt="<?php print $search_description ?>" />
          <input class="form-submit" type="submit" value="<?php print $search_button_text ?>" />
        </div>
      </form><?php } ?>

This is located in the page.tpl.php file in the theme directory.

Or you could turn off the search box within your settings forcing the newly added one to appear.

This would need a bit of tidying up but this is the code they ask you to insert dependent on the options you chose, again yours may differ but the idea is the same:

Note line 2. That's the URL of the search result page.

<!-- SiteSearch Google -->
<form method="get" action="http://www.sitename.com/googlesearch.htm" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">

</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="www.sitename.com"></input>
<input type="text" name="q" size="20" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Google Search"></input>
</td></tr>
<tr>
<td>&nbsp;</td>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" checked="checked"></input>
<font size="-1" color="#000000">Web</font>
</td>
<td>
<input type="radio" name="sitesearch" value="www.sitename.com"></input>
<font size="-1" color="#000000">www.sitename.com</font>
</td>
</tr>
</table>
<input type="hidden" name="client" value="pub-5006751382868565"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="safe" value="active"></input>
<input type="hidden" name="flav" value="0000"></input>
<input type="hidden" name="sig" value="oxG6OMSGsV1OFRVy"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11"></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->

Hope this helps.

Cromicon’s picture

Except it doesn't work. The URL generated by the search *should* feed into the script on the results page within the IFRAME but Drupal returns a 404 error.

Any ideas folks?

steve22’s picture

It does not work with mine either. I have saved the result code in a page called "google" at http:// mysite.org/google. The search results in following url:
http:// mysite.org/google?domains=mysite.org&q=searchterms&sitesearch=&sitesearch=mysite.org&sa=Search&client=pub-xxxxxxxxxxxxx& ..

And it gives "page not found" error.

Cromicon’s picture

See this link for some clues... and untested module code (at the time of this post)
http://drupal.org/node/78888
Maybe it will help.

techmag’s picture

mittalpatel’s picture

It worked perfectly for me. I just changed q with as_q and it started showing me the desired search page http://www.share-ebooks.com/search . Thanks a ton.

And Mr. Techmag, your site isn't showing this page now(as you deleted your data by mistake :-( ). I found your blog on some other site and followed the instruction. So it will be helpful to other people if you make your page up as soon as possible so that they won't need to wander much.

Anyways, Thanks again.

- Mitsss
http://www.MittalPatel.co.in

gafir777’s picture

Thanks Mittal, it just worked perfect!

Loic

afagioli’s picture

that works fine! thanks

marcoBauli’s picture

The "as_q" tip works fine for an on-site search but once someone adds your CSE to their Google Homepage and tries to use it as a Google Gadget and searches it still implements the "q" variable.

Any ideas? thank you very much for any help