Justin Cutroni propose a way to track searches that don’t produce any results:
http://www.epikone.com/blog/2009/09/08/tracking-ero-result-searches-in-g...

Comments

hass’s picture

Title: Interesting feature: Tracking Zero Result Searches » Tracking Zero Result Searches

Interesting... and the most difficult part will be to get out if there are search results or not.

Please provide a patch.

hass’s picture

This is very specific to themes... not sure how to solve. Aside you can implement it with custom javascript before and after snippets... it would only looks not very nice :-(. At least "sn" and the regex need to be changed for Drupal... 'content' ID may be unavailable in a theme and 'Your search yielded no results' may be translated and a bit more issues...

Snippet (Before):

var content = document.getElementById('content');
if (content.innerHTML.search('Your search yielded no results')) {
     // These lines get the search data from the URL and 
     //  deconstruct the URL into parts 
     var sn = "s"; 
     var sr = new RegExp(sn+"=[^\&]+"),
      p = document.location.pathname,
      s = document.location.search,
      sm = s.match(sr).toString(),
      srs = sm.split("="),
      // The next line is where we add the category and add
      // the phrase no-results to the search term.
      sre = sm.replace(sr,srs[0]+"=no-results: "+srs[1]+"&cat=no-results"),
      sf = s.replace(sr,sre);
      // Send the data to Google as a Pageview
      pageTracker._trackPageview(p+sf);
} else {
      // If this is a regular page on the site, use the standard GA code.

Snippet (After):

}
Anonymous’s picture

I see, there's not a easy way on drupal :(

Thanks for the code

hass’s picture

Status: Active » Closed (works as designed)

As said - this *hardly* depends on theme HTML code. I have no idea how to implement this in a generic way if core does not provide us the number of found results in a hook or via a function calll :-(. If someone is able to come up with a way I would be happy to implement this.

hass’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Closed (works as designed) » Postponed

Let's investigate if there is a way in D7...

hass’s picture

Status: Postponed » Active

Found something, but need to dig deaper... And do some testing

http://api.drupal.org/api/drupal/modules--search--search-results.tpl.php... with Your search yielded no results.
http://api.drupal.org/api/drupal/modules--search--search.pages.inc/funct...

hass’s picture

Implemented search result counter in piwik successfully. Can be ported, but I would also be interested to always get the results and not only if there is no result.

hass’s picture

Status: Active » Fixed

Committed to D6 and D7

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.