chevron-down chevron-right chevron-left close minus plus check dollar facebook twitter linkedin search dots

Track Zero Search Results In Google Analytics

Why site search analytics matter

Congratulations! If you’re here, you have just setup a new search tool, or are looking to connect it with your website for the first time. You have made it much easier for your users to navigate your website.

But here comes the next step — do you know what people are searching for and finding? Or worse, what they’re not finding?

Search is often the last resort on a website when users have been unable to find what they’re looking for. If you don’t have what users are searching for, they are likely to get frustrated and leave your website, never to return.

BUT if you are tracking what users are searching for, and which results perform the best, you can use them to improve your site and thereby convert more users to paying customers.

Consider the case where you sell womens and mens shoes. If in the last month 100 people have searched for kids shoes, you might consider whether or not you should begin selling kids shoes.

In an other example you might have an online shop selling beverages. People are searching for “energy drink”, but don’t find anything even though you sell Red Bull. In this case you might want to optimize your search product. A solution is to add a synonym, so when people search for energy drinks they will also find Red Bull.

Well enough talk. Let’s explain how you can track your search results in Google Analytics with your own search engine, and then afterwards show how easy it is with Cludo.

How to enable Google Analytics Site Search

The first step is to enable Site Search in Google Analytics. Log into your Google Analytics account and follow these steps:

1)   Chose admin from the bottom left menu

2)   Click view settings

3)   Click ON for Site search Tracking

4)   After you have Site search Tracking enabled set the query parameter you use for your search queries. For Cludo it is setup as cludoquery. That means that the search url looks like this:
https://www.cludo.com/searchresults#?cludoquery=pricing&page=1

Note: The query parameter cludoquery is actually telling the search server what to search for.

You can also choose to enable categories (facets), which in Cludo is called cludofacets (e.g. https://www.cludo.com/searchresults#?cludoquery=pr&cludofacets=Features&page=1)

By following these steps, you can under reports, see what the users actually search for:

Setup zero results tracking in Google Analytics

Now that you have Site Search enabled in Google Analytics, we just need to help Google track when a user doesn’t get any results for a search.

Note: We are basing this post on the newer Universal Google Analytics script. If you are using the Classic Google Analytics script the event tracking syntax is a bit different. You can see the how event tracking is done in the Classic version here: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

The way you track zero results in Google Analytics is to use event tracking. Usually when a user searches and doesn’t find any results, there will be a standard text message stating, “Sorry, no results were found“. We want to find the container with that text so we can place an ID on it. In your website’s HTML that container could look like this:

<h2 id=”zeroSearchResultsContainer”>Sorry, no results were found</h2>

The easiest way to do this is to add an ID to the container of the text (see the above html-snippet), and run an event for the container to be found. If the container is found, it means that there were no search results. To get the actual query that didn’t return any results, you can (usually) look in the URL. Here is an example where we get it from the query parameter called ‘cludoQuery’. (Thanks to http://stackoverflow.com/a/901144/79465):

(function(){

            function getParameterByName(name) {

           name = name.replace(/[\[]/, “\\[“).replace(/[\]]/, “\\]”);

           var regex = new RegExp(“[\\?&]” + name + “=([^&#]*)”),

       results = regex.exec(location.search);

           return results === null ? “” : decodeURIComponent(results[1].replace(/\+/g, ” “));

            };

            window.onload = function(){

                        if(document.getElementById(‘zeroSearchResultsContainer’) != null){

                                    var searchQuery = getParameterByName(‘cludoQuery’);

                                    ga(‘send’, ‘event’, ‘Search’,’ZeroResults’, searchQuery  ? searchQuery : ‘Blank’);

                        }

            };

})();

Notice that we are looking for a container with the Id called ‘ZeroSearchResultsContainer’ and the URL parameter is ‘cludoQuery’. If we find the container it means that there weren’t any search results found, and we can send an event to Google Analytics.

Save the script in a JavaScript file, and include it on your search result pages, and you are done.

You can now log into Google Analytics and see the searches that produce zero search results.

Google Analytics integration for Cludo

Update: We now also support Siteimprove Analytics!

If you use Cludo, you already have a detailed Analytics dashboard. If you still want to use Google Analytics, you just have to enable Site Search (see the first section), and then enable tracking of zero results with one click in the website settings field – it doesn’t get much easier.