Skip to content

Commit 04b85e0

Browse files
authored
Merge pull request #1173 from ethereum/remove-empty-searches
Exclude empty search queries from analytics [Fixes #1153]
2 parents 2d7d33c + 698d49f commit 04b85e0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/Search/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,23 @@ const Search = ({ handleSearchSelect }) => {
197197
const ref = createRef()
198198
const [query, setQuery] = useState(``)
199199
const [focus, setFocus] = useState(false)
200-
const searchClient = algoliasearch(
200+
const algoliaClient = algoliasearch(
201201
process.env.GATSBY_ALGOLIA_APP_ID,
202202
process.env.GATSBY_ALGOLIA_SEARCH_KEY
203203
)
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+
}
204217
useOnClickOutside(ref, () => setFocus(false))
205218

206219
const handleSelect = () => {

0 commit comments

Comments
 (0)