File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -197,10 +197,23 @@ const Search = ({ handleSearchSelect }) => {
197
197
const ref = createRef ( )
198
198
const [ query , setQuery ] = useState ( `` )
199
199
const [ focus , setFocus ] = useState ( false )
200
- const searchClient = algoliasearch (
200
+ const algoliaClient = algoliasearch (
201
201
process . env . GATSBY_ALGOLIA_APP_ID ,
202
202
process . env . GATSBY_ALGOLIA_SEARCH_KEY
203
203
)
204
+ const searchClient = {
205
+ search ( requests ) {
206
+ const newRequests = requests . map ( ( request ) => {
207
+ // test for empty string and change request parameter: analytics
208
+ // https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/out-of-the-box-analytics/how-to/how-to-remove-empty-search-from-analytics/#exclude-searches-from-your-analytics
209
+ if ( ! request . params . query || request . params . query . length === 0 ) {
210
+ request . params . analytics = false
211
+ }
212
+ return request
213
+ } )
214
+ return algoliaClient . search ( newRequests )
215
+ } ,
216
+ }
204
217
useOnClickOutside ( ref , ( ) => setFocus ( false ) )
205
218
206
219
const handleSelect = ( ) => {
You can’t perform that action at this time.
0 commit comments