How to Remove the Empty Search from Analytics
On this page
When you look at your analytics on the Algolia dashboard, it’s likely that one of the top-ranked queries is <empty search>
.
This is often the top search if you use Algolia to offer a search-as-you-type experience to your users. This is because such experiences trigger a search request even before users start typing to instantly show results.
Depending on your use case, the empty search can tell you something about the relevance of your index. For example, for an ecommerce store it could be valuable to see how people interact with an empty search. It can show whether the products that show up first on an empty search are popular or not. For a blog, this metric might not be so useful. Most blogs sort articles by publication date, so empty search metrics give little insight into relevance.
You can exclude the empty search from your analytics if you want to. Before you decide to do so, please make sure that it does lack any analytical value for your project.
Exclude searches from your analytics
To exclude certain queries from your analytics, you have to pass the analytics
parameter with false
as a value.
The following example shows how to remove empty query searches, but you can change the query to suit your needs.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const algoliasearch = require('algoliasearch/lite');
const instantsearch = require('instantsearch.js').default;
import { searchBox, hits, pagination } from 'instantsearch.js/es/widgets';
const algoliaClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
const searchClient = {
search(requests) {
console.log(requests)
const newRequests = requests.map((request)=>{
// test for empty string and change request parameter: analytics
if(!request.params.query || request.params.query.length===0) {
request.params.analytics=false
}
return request
});
return algoliaClient.search(newRequests);
},
};
const search = instantsearch({
indexName: 'Books',
searchClient,
});
search.addWidgets([
searchBox({
container: '#searchbox',
}),
hits({
container: '#hits',
templates: {
item: `
{{title}}
`,
},
}),
pagination({
container: '#pagination',
})
]);
search.start();
If you want to prevent sending empty queries altogether, you can turn off search on empty queries.