To get Google Custom Search terms to show up in Google Analytics, you need to have the custom search submit URL parameters to your site that Google Analytics can read.
The code for the search box on my site looks something like this:
<form action="/search" id=search-form>
<input type=hidden name=cx value="partner-pub-123456789:987654321">
<input type=hidden name=cof value="FORID:10">
<input type=hidden name=ie value=UTF-8>
<input type=text name=q size=16 placeholder=search>
<input type=submit value=Search>
</form>
You would have to replace the partner-pub
id with your own custom search id. Note that I'm not using any of the JavaScript that Google gives you by default to show the search results in a lightbox on the current page. When I use that form, it causes the search to submit back to my site at the url:
/search?cx=partner-pub-123456789:987654321&cof=FORID:10&ie=UTF-8&q=search+term
The /search
page has both the snippets for Google Analytics and Google Custom search on it. The custom search snippet is:
<div id=cse-search-results></div>
<script type="text/javascript">
var googleSearchIframeName = "cse-search-results";
var googleSearchFormName = "cse-search-box";
var googleSearchFrameWidth = 800;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
which instructs it to write the search results into the empty div named cse-search-results
.
Because the search term is in the q
parameter, Google Analytics also picks up on it.