Skip to content

Commit 6a532d7

Browse files
authored
Add search event to Hydro (#16157)
* Add search event * Lint fixes
1 parent 054b0d5 commit 6a532d7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

javascripts/search.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { sendEvent } from './events'
12
const instantsearch = require('instantsearch.js').default
2-
const { searchBox, hits, configure } = require('instantsearch.js/es/widgets')
3+
const { searchBox, hits, configure, analytics } = require('instantsearch.js/es/widgets')
34
const algoliasearch = require('algoliasearch')
45
const searchWithYourKeyboard = require('search-with-your-keyboard')
56
const querystring = require('querystring')
@@ -162,6 +163,15 @@ export default function () {
162163
autofocus: (hasStandaloneSearch()) && !window.location.hash.length,
163164
showReset: false,
164165
showSubmit: false
166+
}),
167+
analytics({
168+
pushFunction (params, state, results) {
169+
sendEvent({
170+
type: 'search',
171+
search_query: results.query
172+
// search_context
173+
})
174+
}
165175
})
166176
]
167177
)

0 commit comments

Comments
 (0)