Modify the search function using the 'beforeInstantsearchInit' custom event.
The new function should include a condition that checks to see if there is a query populated; if not, the analytics parameter is set to false.
For example:
const search = instantsearch({
appId: 'XXX',
apiKey: 'XXX',
indexName: 'XXX',
searchFunction: function(helper) {
if (helper.state.query === '') {
helper.setQueryParameter('analytics', false).search();
} else {
helper.search();
}
},
});
For more information, please review our guide on excluding empty searches in analytics.