@@ -88,7 +88,7 @@ export function Search({
8888 case 'Enter' :
8989 // look for a link in the given hit, then visit it
9090 if ( results === null || activeHit === 0 || ! results . length ) break
91- window . location . href = results [ activeHit - 1 ] ?. url
91+ onGotoResult ( results [ activeHit - 1 ] ?. url , activeHit )
9292 break
9393 }
9494 }
@@ -159,6 +159,20 @@ export function Search({
159159 evt . preventDefault ( )
160160 }
161161
162+ function onGotoResult ( url : string , index : number ) {
163+ if ( results ) {
164+ sendEvent ( {
165+ type : EventType . searchResult ,
166+ search_result_query : Array . isArray ( query ) ? query [ 0 ] : query ,
167+ search_result_index : index ,
168+ search_result_total : results . length ,
169+ search_result_rank : ( results . length - index ) / results . length ,
170+ search_result_url : url ,
171+ } )
172+ }
173+ document . location . href = url
174+ }
175+
162176 const SearchResults = (
163177 < >
164178 < div
@@ -176,6 +190,7 @@ export function Search({
176190 results = { results }
177191 activeHit = { activeHit }
178192 setActiveHit = { setActiveHit }
193+ onGotoResult = { onGotoResult }
179194 />
180195 </ div >
181196 { /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
@@ -244,12 +259,14 @@ function ShowSearchResults({
244259 results,
245260 activeHit,
246261 setActiveHit,
262+ onGotoResult,
247263} : {
248264 isOverlay : boolean
249265 isLoading : boolean
250266 results : SearchResult [ ] | null
251267 activeHit : number
252268 setActiveHit : ( index : number ) => void
269+ onGotoResult : ( url : string , index : number ) => void
253270} ) {
254271 const { t } = useTranslation ( 'search' )
255272
@@ -286,7 +303,14 @@ function ShowSearchResults({
286303 onMouseEnter = { ( ) => setActiveHit ( index ) }
287304 >
288305 < div className = { cx ( 'py-3 px-3' , isActive && 'color-border-secondary' ) } >
289- < a className = "no-underline color-text-primary" href = { url } >
306+ < a
307+ className = "no-underline color-text-primary"
308+ href = { url }
309+ onClick = { ( event ) => {
310+ event . preventDefault ( )
311+ onGotoResult ( url , index )
312+ } }
313+ >
290314 { /* Breadcrumbs in search records don't include the page title. These fields may contain <mark> elements that we need to render */ }
291315 < div
292316 className = { 'd-block opacity-60 text-small pb-1' }
0 commit comments