Tracking Zero Result Searches

jmesam - October 24, 2009 - 18:33
Project:Google Analytics
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

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...

#1

hass - October 25, 2009 - 00:26
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.

#2

hass - October 25, 2009 - 01:00

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):

}

#3

jmesam - November 18, 2009 - 02:50

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

Thanks for the code

 
 

Drupal is a registered trademark of Dries Buytaert.