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 users start 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 users are actively searching
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:
importalgoliasearchfrom'algoliasearch/lite';importinstantsearchfrom'instantsearch.js';constalgoliaClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');constsearchClient={...algoliaClient,search(requests){constnewRequests=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;}returnrequest;});returnalgoliaClient.search(newRequests);},};constsearch=instantsearch({indexName:'instant_search',searchClient,});search.addWidgets([/* ... */]);search.start();
importalgoliasearchfrom'algoliasearch/lite';import{InstantSearch}from'react-instantsearch';constalgoliaClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');constsearchClient={...algoliaClient,search(requests){constnewRequests=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;}returnrequest;});returnalgoliaClient.search(newRequests);},};functionApp{return(<InstantSearchsearchClient={searchClient}indexName="instant_search">{/* ... */}</InstantSearch>);}
<template><ais-instant-search:search-client="searchClient"index-name="instant_search"><!-- ... --></ais-instant-search></template><script>importalgoliasearchfrom'algoliasearch/lite';import'instantsearch.css/themes/satellite-min.css';constalgoliaClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');constsearchClient={...algoliaClient,search(requests){constnewRequests=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;}returnrequest;});returnalgoliaClient.search(newRequests);},};exportdefault{data(){return{searchClient,};},};</script>
import{Component}from'@angular/core';importalgoliasearchfrom'algoliasearch/lite';constalgoliaClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');constsearchClient={...algoliaClient,search(requests){constnewRequests=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;}returnrequest;});returnalgoliaClient.search(newRequests);},};@Component({selector:'app-root',templateUrl:'./app.component.html',styleUrls:['./app.component.css']})exportclassAppComponent{config={indexName:'instant_search',searchClient};}