WordPress site search sucks out of the box, but with a few improvements, it can end up rendering some fairly decent result sets.
The usual method most people use to track their WordPress site search is the WordPress Search Meter Plugin. This is an easy way to get some feedback on how your users are utilizing your site search, but don’t you know that Google Analytics can track site search for you?
As great as Search Meter is, Google Analytics is the ideal place to track your onsite search. Not only can you capture the search phrases used, but I will show you how to capture the number of results in the search result set. This will let you identify all the null search terms used on your site and also see the number of results for popular phrases, and which phrases may be returning too many results.
The first step to tracking site search in Google Analytics is to edit your website profile information and and select Do Track Site Search, and put in s as the Query Parameter.
The Query Parameter input is the only thing necessary for Google Analytics to start tracking your WordPress search results, but notice we also added a Category Parameter called numResults and set that parameter to be stripped out from the URL.
Then we are going to edit the template code where the search results are displayed. Some themes have a search results template, some display search results from a main template, but this code block should work inserted into either.
Finally, you need to edit your Google Analytics code usually placed in your footer template. Make sure you don’t paste this in verbatim, as you need to maintain your unique GA id.
We are going to add a switch statement, and send a different request if the page is a search results page.
Once Google Analytics starts reporting on your search results, you can break down search terms by number of results or number of results by search terms.
You can then click on the different number of results to see the search terms used. In a future post, I’ll show you how you can use this same GA switch statement for 404 page tracking.