Analytics

Track Zero Search Results In Google Analytics

This blog explains how you can track your search results in Google Analytics with your own search engine, as well as how easy it is with Cludo.


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?

Why site search analytics matter

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 women's and men's 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. (Note: these directions are for GA4).

Log into your Google Analytics account and follow these steps:

1)   Chose Admin from the bottom left menu

2)   Under Property, click Data Streams

3)   Choose the property you want to turn site search on for

4)   Under Enhanced Measurement, click the settings icon

5)   Toggle ON for Site search Tracking

GA4 Directions

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, under reports you can 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

We also support Siteimprove Analytics!

Data Settings New UI

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.

Similar posts

Get notified on new content from Cludo

Be the first to know about the world of search and analytics. 

Subscribe now!