So I'm trying to set the query parameters and category parameters for google custom search. Here is an example search results page url:
http://www.whiterootmedia.com/search_results/index.html?q=my%20search%20phrase
So it looks like the default query parameter is q so I put q in the box when setting up the analytics portion for my google custom search engine. Is this ok? I read it wasn't ok to use q but to instead use query? And why does it matter?
Also should I set a category parameter that looks to be optional.
Thanks,
Dusty
The Google Search API just uses q. AFAIK the API doesn't have a query parameter. Check out the custom search API documentation.
Not sure what you mean by the 'category' parameter. Haven't come across that one before.
HTML:
<gcse:search gname='google1'></gcse:search>
Javascript:
window.google.search.cse.element.getElement("google1").execute("hello world");
But you need to wait for the Google script to load before launching the javascript.
If you use searchresults-only instead of search, you also need to enable the correct layout in the CSE Control Pannel: https://www.google.com/cse/
You can hit the following: https://cse.google.com/cse?as_q=your_query_string%20must_be_urlencoded&client=google-csbe&cx=full_cse_id_goes_here:including_the_bit_after_the_colon
So a direct answer to your question - the query parameter key is 'as_q'.
Related
I've been working with Google Custom Search API and faced some inconveniences I hope you can help me with.
Google Custom Search API offers as a parameter in its call the possibility to search by an exact text as well as exclude it from results: exactTerms and excludeTerms. However, the q parameter is mandatory and cannot be ignored, so if I want to search only by an specific text I just can't.
So how can I do a query using JSON API that contains specifically the text I want? Does the q parameter work as the search form in Google?
If I want results including 'foo', should I do this:
service.cse().list(cx=const.SEARCH_ENGINE_KEY, q='"foo"').execute()
or this?:
service.cse().list(cx=const.SEARCH_ENGINE_KEY, q=None, exactTerms='foo').execute()
Thank you in advance for your time.
Due to the success on the answers (hehe) I'm posting my own conclusions. Please, if you've any facts regarding the original question, please post it.
I've been testing with some calls to Google CSE API and looks like you can pass to q parameter the same query you'd do in Google's main page textfield. So (at least for my needs), you don't need exactTerms and excludeTerms to get what I was trying to achieve.
Anyway, as I said before, if you know how to work with these parameters I'm sure everybody will thank you.
When I search for "football images" on google.co.uk, it knows that I mean the sport that elsewhere might be called "soccer". If I do the same search on google.com, I get American Football.
I'm using the custom search API - how can I tell it that I'm in the UK and would like results relevant to here?
You can limit your engine to operate on sites from a particular country via "cr" param, e.g. in Custom Element it looks like this:
<gcse:search cr="gb"></gcse:search>
Google knows some synonyms on the web, but if your particular use case is not correctly recognized you can add it in Control Panel in Search Features > Synonyms
More on synonyms:
Sorry, I ended up answering this myself. I couldn't get any of the instructions under the custom search API itself to work (although the answer offered above was also mentioned there, but this just made my CSE Context XML apparently invalid), but you can make requests to a custom search engine by using the instructions here https://developers.google.com/custom-search/json-api/v1/using_rest and an API key.
This is how I did it;
<gcse:search cr="countryUK"></gcse:search>
You can even return results in a specific language, code shown below returns results only in french;
<gcse:search lr = "lang_fr"></gcse:search>
This is the reference for Google Custom Search Element Control API: https://developers.google.com/custom-search/docs/element?hl=en
Try to set the 'gl' parameter to the country you want.
For details, look into CSE:list
I am in need of implementing google analytics on a site where i have my own search functionality, and i would like to have the ability to tell analytics what the users are searching in the internal seaching, so i can catch the search terms and other interesting stuff.
So the buttom line is that when the users are searching with the internal search, this should be shown inside google analytics, which terms they used, which page them came to and so on.. All the stuff that google's own search implements.
Others must have done this, but i can't find the right information.
thanks in advance!
As Eike Pierstorff mentioned in his comment, within the interface you can set GA to look for a parameter in the URL. So if your site search already passes the search term as a query string parameter, just set GA to look for that parameter and you should be good to go.
If your site search does not push the search term to a query string parameter (e.g. it's AJAX based or simply doesn't do it), you can push it to the _trackPageview call.
Example:
// do what you have to do to populate this variable with the search term
var searchTerm='search term here';
var pageName = location.pathname+location.search;
pageName += (location.search) ? '&' : '?';
pageName += 'q='+searchTerm;
_gaq.push(['_trackPageview', pageName])
Then in the GA interface, set GA to look for the "q" parameter.
A simple way to do it is to send a custom Event whenever your search button is pressed or when the results are shown.
Add the search string as the Event Label.
You will then see the website searches on the Behavior->Events section.
I want to use the Google Custom Search API (or custom search engine directly) in the following manner--
(1) I want to get the set of results for a search term for Google UK(This should return results that are returned by a regular search on Google.co.uk- Google UK)
(2) I want to get the results for a search on Google.co.in(Google India)
Is it possible to do the above, either directly while creating a custom search engine, or through the API?
Yes. It is possible. Specifiy the parameter googlehost in your query. Example: &googlehost=google.de or whatever country you want.
It is in the settings, can change from the Control Panel.
I am using Google's custom search API, I make an HTTP request to a URL that looks like this:
https://www.googleapis.com/customsearch/v1?key=<my-key>&cref=&num=10&q=how+can+i+do+htis
if you search for "how can i do htis" on Google you are told "Showing results for how can i do this", and give you some results (call them result set A)
but if you use the API to search for the misspelled string, you get different results than those of A... Searching with a correctly spelled string gives you result A, which matches the ordinary search service on Google
Is there a way to search directly using the suggested string? I want to use the API I can't afford implementing a spell checker myself that can also correct people names and everything
I think what you want to do is possible using the spelling suggestions of Google. This is part of the xml-results returned by your query.
See API here.