Google Site Search未将结果传递给Google搜索帐户

时间:2012-09-18 20:21:36

标签: search google-analytics

请考虑以下问题(问题是,我们网页上的Google搜索结果未在我们的Google Analytics帐户中注册):

HTML FORM:

    <div style="float:right; margin-right:12px;">
    <form id="cse-search-box" name="srchfrm" action="http://google.com/cse" target="_blank" onsubmit="validatesearch()">
        <input value="999999999999999999999:srraaaaaaaa" name="cx" type="hidden"/>
        <input id="q" name="q" type="text" onKeyPress="return submitenter(this,event)" placeholder="Search"/>
        <a href="javascript:;" onmouseover="MM_swapImage('go','','/btn_go_on.gif',1)" onmouseout="MM_swapImgRestore()" />
        <input type="image" src="/btn_go.gif" alt="Go" width="20" height="21" border="0" align="top" id="go"/>
        <input value="UTF-8" name="ie" type="hidden"/>    
    </form> 
</div>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('search', '1');
  google.setOnLoadCallback(function() {
    google.search.CustomSearchControl.attachAutoCompletion(
      '999999999999999999999:srraaaaaaaa',
      document.getElementById('q'),
      'cse-search-box');
  });
</script>

执行搜索的网址

http://www.google.com/cse?cx=999999999999999999999:srraaaaaaaa&q=test+search&x=12&y=11&ie=UTF-8&oq=&gs_l=#gsc.tab=0&gsc.q=test%20search&gsc.page=1

正在使用的查询参数:

q
query (I read in another post to try this)

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

通过更改:

action="http://google.com/cse"

<form id="cse-search-box" name="srchfrm" action="http://google.com/cse" target="_blank" onsubmit="validatesearch()">

要重定向到网站中的网页,这就解决了这个问题。

工作代码:

<div style="float:right; margin-right:12px;">
    <form id="searchbox_99999999999999999999:srraaaaaaaa" name="srchfrm" action="/search" target="_self" onsubmit="validatesearch()">
        <input value="99999999999999999999:srraaaaaaaa" name="cx" type="hidden"/>
        <input id="q" name="q" autocomplete="off" type="text" onKeyPress="return submitenter(this,event)" placeholder="Search"/>
        <input name="ie" value="UTF-8" type="hidden"/>
        <a href="javascript:;" onmouseover="MM_swapImage('go','','/btn_go_on.png',1)" onmouseout="MM_swapImgRestore()" />
        <input type="image" src="/btn_go.png" alt="Go" width="20" height="21" border="0" align="top" id="go"/> 
    </form> 
</div>

根据Google文档,搜索页面本身具有以下代码:

HEAD:

<script>
  (function() {
    var cx = '99999999999999999999:srraaaaaaaa';
    var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
  })();
</script>

BODY:

<gcse:searchresults-only></gcse:searchresults-only>