Free tech support / small logo


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!









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments
Rather amazingly, there are no comments on this article yet.

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

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











Remember personal info?


Please note that I will never send you any unsolicited 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.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 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]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.