customSearchControl.execute with Adsense

141 views
Skip to first unread message

MrSulo

unread,
Jun 20, 2010, 5:18:10 AM6/20/10
to Google AJAX APIs
Hi all,
when i start the Google search with this code ..


function test_start()
{
google.load(
"search", "1",
{ "language" : "de",
"callback" : "apiLoaded"
});
}
function apiLoaded()
{
var customSearchControl = new
google.search.CustomSearchControl('0038726555587615084:qeryjmqhn2e');

customSearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
customSearchControl.draw('g_results');
customSearchControl.addSearcher(new google.search.ImageSearch());
customSearchControl.addSearcher(new google.search.NewsSearch());
customSearchControl.addSearcher(new google.search.BlogSearch());
customSearchControl.addSearcher(new google.search.BookSearch());
customSearchControl.execute('test');
}

i didnt get the Adsense Ads... only when i press the search button.
But why?

Greetz from Germany
MrSulo


Adam Feldman

unread,
Jun 20, 2010, 5:24:16 AM6/20/10
to Google AJAX APIs
Hello,

Ads are designed to only be shown when your site's visitors actually
perform searches of their own. You can do default searches with
the .execute method, but users will only see an ad if they do a
subsequent search that they've entered themselves.

Please don't attempt to circumvent this behavior - doing so could be
considered a violation of the ads policy and be cause for suspension
of access to the API.

Thanks!
Adam

MrSulo

unread,
Jun 20, 2010, 6:02:08 AM6/20/10
to Google AJAX APIs
Thanks for the fast answer.
I have an own Input-Text-Field. It is possible to start the search
from this form?

Kind Regards
sulo

Adam Feldman

unread,
Jun 20, 2010, 6:07:28 AM6/20/10
to Google AJAX APIs
I'm not sure I know exactly what you mean, but if I understand
correctly, this blog post should help you out:
http://googleajaxsearchapi.blogspot.com/2009/08/custom-search-with-custom-style-peanut.html

If it doesn't, then can you give some more details on what you're
looking for?

Cheers,
Adam

MrSulo

unread,
Jun 20, 2010, 8:08:23 AM6/20/10
to Google AJAX APIs
My last question :)

Is it possible to say "start search" bei click on a button. I dont
want the autosearch (onkeyup).

Thanx 4 the fast help!

cheers,
sulo

Jeff S (Google)

unread,
Jun 21, 2010, 3:55:06 PM6/21/10
to google-ajax...@googlegroups.com
Hi sulo,

The custom search control assumes that if you specify your own input box, you want to search as you type. You can override this behavior on your own and add your own logic if you like. The first step could be removing the onkeyup handler that the custom search control adds to your input box. This might look something like

document.getElementById('query_input').onkeyup = null;

Or you could add your own onkeyup handler. From there you can add your own logic to submit or execute the query.

Happy coding,

Jeff

sulo

--
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To post to this group, send email to google-ajax...@googlegroups.com.
To unsubscribe from this group, send email to google-ajax-searc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-ajax-search-api?hl=en.


MrSulo

unread,
Jun 23, 2010, 8:56:40 AM6/23/10
to Google AJAX APIs
Hi Jeff,

> Or you could add your own onkeyup handler. From there you can add your own
> logic to submit or execute the query.

sounds nice :) .... but how can i start a submit?

<script src="http://www.google.com/jsapi" type="text/javascript"></
script>
<script type="text/javascript">

google.load('search', '1');
function onLoad()
{
var customSearchControl = new
google.search.CustomSearchControl('006146383332072746140:rc7_dtmydr0');
customSearchControl.enableAds(/* put your publisher ID here */);
var drawOptions = new google.search.DrawOptions();
// drawOptions.setInput(document.getElementById('query_input'));
drawOptions.setInput(document.getElementById('query_input').onkeyup =
null;);
customSearchControl.draw('results', drawOptions);
}
google.setOnLoadCallback(onLoad);


function go_google_go()
{
// Start search
document.form.submit(); // ?
}
</script>

<input type="text" id="query_input" name="query_input"
onkeyup="go_google_go();" value="" />
<div id="results"></div>


kind regards
Sulo

Jeff S (Google)

unread,
Jun 23, 2010, 1:58:05 PM6/23/10
to google-ajax...@googlegroups.com
Hi Sulo,

To submit the user's query you can use customSearchControl.execute(
usersQuery); so you might need to do something like making the customSearchControl a global or use a closure to reference it in your go_google_go function.

Thank you,

Jeff



--

MrSulo

unread,
Jun 23, 2010, 3:17:22 PM6/23/10
to Google AJAX APIs
no, thank you !

// To submit the user's query you can use customSearchControl.execute

Ok, it works, but i have the same problem.

Quote:
Adam Feldman wrotes " You can do default searches with the .execute
method, but users will only see an ad if they do a subsequent search
that they've entered themselves."

I think there is no way to start a search with an own input field and
ads by pressing a submit button?
Right?

kind regards,
sulo

Reply all
Reply to author
Forward
0 new messages