View Full Version : Save what people search for on your SW
IntroSites
05-01-08, 03:28
The following code will save search queries , number of results, date and visitors ip
add the following to the bottom of search.php just before ?>
/* Start IntroSites Search Spy
* create a csv file in your public_html directory and chmod it 777
* to keep your searches private use a different name eg: blahblah.csv instead of searches.csv
*/
$_file = 'searches.csv'; //
$_fp = @fopen( $_file, 'a' );
$_csv_data=date("d/m/y").',"'.$_GET['q'].'",'.intval($oProductListResponse->iTotalCount).','.$_SERVER['REMOTE_ADDR']. "\n";
@fwrite( $_fp, $_csv_data );
@fclose( $_fp );
/* End IntroSites Search Spy */
remember to create the file as explained above
View the file at http://www.example.com/searches.csv or whatever filename you used
Hope this is of help to some of you.
Cheers :D
What an impressive little piece of code Intro.
Makes for some interesting reading and so simple even I could implement it!
Yet again, thanks very much for sharing your expertise with us.
Nice work - Appreciated
Bud :D
Nice one, thanks for that, that should make pretty interesting reading. :)
Confuscius
07-01-08, 14:32
Just a word of caution on using this code - IF you generate links that use the 'q' variable then I believe that search engine spider visits will get logged but if you know the SE IP addresses then you can ignore them. I would love to know the proportion of page loads from 'searching' compared to 'browsing'.
Not being a programmer, I wonder if there is a way to capture them ONLY when the search button is clicked or include a 'type' in the log? Steve, any suggestions/ideas/code?
Paul
IntroSites
07-01-08, 15:09
You could check for a referer, not 100% as some users block referers, but it should keep the bots out the log
if($_SERVER["HTTP_REFERER"]){
$_file = 'searches.csv'; //
$_fp = @fopen( $_file, 'a' );
$_csv_data=date("d/m/y").',"'.$_GET['q'].'",'.intval($oProductListResponse->iTotalCount).','.$_SERVER['REMOTE_ADDR']. "\n";
@fwrite( $_fp, $_csv_data );
@fclose( $_fp );
}
Hi Intro,
Just wanted to say well done for the coding, looks like a great tool for capturing some very useful data.
This is excellent stuff, hope many will find it useful
Adrian
SW Integration & Technical Support
adrian.botelho@digitalwindow.com
www.digitalwindow.com
Some very funny searches - most amusing :D, some confusing :confused: and a couple of :eek:
Hi Bud,
Im intrigued now - please share ;)
Amo
IntroSites
08-01-08, 16:26
ive had some strange searches too, and some people just dont understand search :eek: "where can i buy some brown cushions to match my sofa and curtains"
You could check for a referer, not 100% as some users block referers, but it should keep the bots out the log
This should be OK as Firewalls don't block the referrer, they just overwrite it. If you were to log referrers, you'll see they tend to overwrite with: XXXX+++++++++++++
I use this idea for discerning whether it's a bot of not:
if(!strpos($_SERVER['USER_AGENT'], "bot"))
All real spiders will have "bot" in their user agent somewhere
the-ferret
10-01-08, 13:33
Preumably you could use javascript to add an onCick event to the search button if you wanted to only capture 'real' user events
One of the interesting things this has highlighted is the large amount of people who click the 'Search' button before entering any search terms.
Typically they seem to select a category from the drop down search and expect all the results - to be honest so would I.
Therefore they are generally returned with '0 items found'.
I've currently got a bit of code in to prompt my visitors to, "Type Your Search in Here..", but this seems to be ignored generally.
Is there anyway I can get the complete category results should a search term not be enetered?
Anyone have any clever ideas?
Thanks
Confuscius
13-01-08, 20:36
The code records all visits not just searches- change the code to check for if q is present first and then only write to the file or record all visits and mark those that had q present with a 'type' in the file.
Paul
Thanks for the comment Paul but I've already taken that into account. There are still plenty of times my visitors just select the category and hit 'Search'. Then, not suprisingly, most leave.
If anyone's not sure what I mean go to:
www.shopwindow.com
Don't enter anything in the search box and select 'Electronics' from the drop down box.
Hit the search icon
'No Results Found'
My stats and tracking indicate this is a very common problem.
I think this should default to:
http://www.shopwindow.com/category.php?c=4
:)
Confuscius
14-01-08, 01:40
Victor Meldrew! :)
http://www.google.co.uk/search?hl=en&q=victor+meldrew+catchphrase&btnG=Search&meta=
IntroSites
15-01-08, 13:23
Thanks for the comment Paul but I've already taken that into account. There are still plenty of times my visitors just select the category and hit 'Search'. Then, not suprisingly, most leave.
If anyone's not sure what I mean go to:
www.shopwindow.com
Don't enter anything in the search box and select 'Electronics' from the drop down box.
Hit the search icon
'No Results Found'
My stats and tracking indicate this is a very common problem.
I think this should default to:
http://www.shopwindow.com/category.php?c=4
:)
Bud, take a look at my site, is this what you're after?
Your coding never ceases to impress me Intro!
That's exactly what I meant.
Much more useful isn't it?
IntroSites
16-01-08, 12:21
at top of search.php before include global.inc.php
if($_GET['q']=="" && $_GET['c']!==""){header("Location: category.php?c=".$_GET['c']);exit;}
if you are sending "Type Your Search in Here" on blank submits you will need to look for it or remove it to detect an empty search.
you could just strip it out by adding $_GET['q'] = str_replace("Type Your Search in Here","",$_GET['q']); above the mod
hth
Fantastic!
As far as I can tell that works a treat. :D
I guess that's another pint (or ten!) I/we owe you.
Really appreciated :)
Paul - That should keep the Victor Meldrew's happy!
Quick update:
I can see a vast difference already in how visitors are using the site - occasional clicks on drop down categories doesn't stop them now, they just refine the search if they want.
Big hugs to Intro for the coding!
nick-harper
16-02-09, 00:28
I just wondered how hard this will be to implement onto an API site?
IntroSites
16-02-09, 09:10
if you have the knowledge to write an API site then implementing this should be a slice of cake ;)