Are visitors using site search on your WordPress site? If so, are they finding what they are looking for? In this article I’ll show you how to configure Google Analytics to track and report on the search terms visitors are entering into your site search that return zero results.
The importance of understanding what content is being searched for on your site cannot be understated. Utilizing Google Analytics to ascertain zero result search terms allows you to tailor your content to fulfill visitor requirements. This article assumes you are already using Google Analytics to track your website activity.
Google Analytics contains a full suite of Site Search reports that are categorized under the Content menu. There are a variety of reports that will show the number of visits that result in a site search, which terms are searched for, the most popular destination pages after a search, and a variety of other metrics related to visitor activity and site search. Google Analytics reports all search terms without distinguishing whether or not any results were found.
Note that Site Search Tracking needs to be configured in your Google Analytics Profile before Google Analytics can report on site search data. However, to implement only zero result search reporting as described in this article, it is not required to have Site Search tracking turned on.
Example of a zero results found message in the search.php file:
To track only site searches that return zero results it is necessary to set-up an event using the Google Analytics Tracking Code (GATC). Using events, Google Analytics is able to record the details for any browser based event. An event is defined as any user activity that does not generate a Pageview , including things like ajax calls, clicking on a user control, as well as when a site search produces zero results. Please keep in mind that, assuming you have the GATC code installed to record Pageviews, the site search itself will be recorded by Google Analytics as a Pageview (or virtual page view depending on your configuration) whether results are found or not. (It is important not to use the GATC _trackPageview method call to record zero search results information as this will inaccurately inflate your Pageview count.)
There are no profile configuration changes required in Google Analytics to track events. It is only necessary to call the _trackEvent method of the GATC. The events will be reported in the Google Analytics Content Menu under Event Tracking.
To summarize Google’s Event Tracking Guide, the _trackEvent method is defined as such:
- category (required) The name you supply for the group of objects you want to track.
- action (required) A string that is uniquely paired with each category and commonly used to define the type of user interaction for the web object.
- label (optional) An optional string to provide additional dimensions to the event data.
- value (optional) An integer that you can use to provide numerical data about the user event.
To record zero result site searches, the _trackEvent method needs to be called within the same logical condition that displayed the ‘No Posts Found’ message in the search.php file.
The code listed above does not initialize the GATC. The _trackPageview method should have already been called from the header section of the search page. As so, the _gaq object is still within scope. The _gaq.push method is what registers the event with Google Analytics. In the _gaq call, set the event category to ‘Search’, the action to ‘ZeroResults’, and the label to the search term.
The gup() function is used to parse the value of the ‘s’ parameter from the URL string. WordPress uses ‘s’ as the default search parameter. You can see this in the URL preceding the search term when you perform a site search (?s=silo). If the search parameter is different for your site it will be necessary to modify the call to gup() with the correct value. Credit for the gup() function belongs to the Netlobo.com site.
It is important to note here that Google recently changed the GATC to operate in asynchronous mode. This means that the browser can continue rendering the page while the GATC operates in the background. It is recommended to place this async call to _trackPageview in the header section of the web page as opposed to the older GATC versions where it is recommended the call be placed right before the closing </body> tag of the page. If you are using a pre-Asynchronous version of the GATC you will need to convert the _gaq.push line in the code listed below as detailed in the Google Analytics Asynchronous Migration Examples.
As you can see from this graphic there were 3 Search events registered.
Clicking on the Actions menu item will show the Total ZeroResults count. This represents the number of searches that returned the ‘No Posts Found’ message.
Drilling down on ZeroResults shows the search terms that yielded zero results.