🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Search analytics / Guides

Exclude search queries from analytics

Sometimes, you might want to exclude specific queries from your analytics. These searches still return results, but they won’t show up in any of the metrics.

To exclude searches from analytics, set the analytics search parameter to false.

Empty searches

Often, one of the top-ranked search queries in your analytics is <empty search>.

Empty searches have two origins:

  • An initial search request with an empty query to instantly show results before the user starts typing
  • Category pages are built with an empty query and an applied filter

In some cases, the empty search might not be relevant. For example:

  • You only show search results when the user actively searches
  • You have an absolute ordering of your search results, such as, a blog search that’s sorted by date

Exclude searches from your analytics

To exclude specific search queries from your analytics, set the analytics parameter to false.

For example, to exclude empty queries from your analytics, create a custom search client and set analytics: false when the query is empty:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import algoliasearch from 'algoliasearch/lite';
import instantsearch from 'instantsearch.js';

const algoliaClient = algoliasearch(
  'YourApplicationID',
  'YourSearchOnlyAPIKey'
);

const searchClient = {
  ...algoliaClient,
  search(requests) {
    const newRequests = requests.map((request) => {
      // Test for empty string and change `analytics` request parameter to `false`
      if(!request.params.query || request.params.query.length === 0) {
        request.params.analytics = false;
      }
      return request;
    });

    return algoliaClient.search(newRequests);
  },
};

const search = instantsearch({
  indexName: 'instant_search',
  searchClient,
});

search.addWidgets([/* ... */]);

search.start();

To prevent sending empty queries altogether, turn off search on empty queries.

Did you find this page helpful?