Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Can I capture Google searches on my site?

I see you've posted articles explaining how to put a Google Search Box and Search Results on a website. (see add Google search to your site). But is it possible to be able to store the search phrases typed into the Google search boxes? This way I can analyze the data to know what people are searching for, then create more content on that subject.


Dave's Answer:

Well, the answer is "yes and no". You can indeed capture the searches people do through a custom Google search box on your site, but it's a bit tricky and you need something that many people don't have, which is the ability to run custom CGI scripts on your Web server.

The basic idea would be that instead of having the search form pointing directly to Google, it will point to a script on your site that captures their search term then hands the search itself along to Google, all in a fraction of a second.

The script has the following line for the search box:

<form method="get" action="http://www.google.com/search">

But if we change that to, say, action="http://www.myserver.com/savesearch.cgi", now we can write that script. Make it a rudimentary shell script and it would look like this:

#!/bin/sh
log="/var/log/searchbox.log"
echo $QUERY_STRING >> $log
echo "Location: http://www.google.com/search&$QUERY_STRING"
echo ""
exit 0

Assuming you have everything set up properly, including the log file being writable by a script launched by the Web server, that's all you would need to be able to have a file called "searchbox.log" that stores all the search patterns people use.

If you prefer Perl, C, or some other scripting language you can definitely accomplish the same with those languages, perhaps even more efficiently, but this gives you a sense of the basic methodology you'd want to use and how it could integrate into your site.

Again, though, let me warn you that it's a lot more complicated than just adding a few lines to a Web page, and if you're not already comfortable monkeying with scripts on your Web server -- and have a Web server that will let you do that! -- then this might not be a good solution for you. Check with your Web hosting provider, they'll be able to let you know if this is something you can do or not!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments
Rather amazingly, there are no comments on this article yet.

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]