File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ import { Dialog } from '@headlessui/react'
22
22
import clsx from 'clsx'
23
23
import { type Result } from '@/markdoc/search.mjs'
24
24
25
- import { flatNavigation , navigation } from '@/lib/navigation'
25
+ import { flatNavigation } from '@/lib/navigation'
26
+ import { track } from '@vercel/analytics'
27
+
28
+ let timer : number | Timer | undefined
29
+ const waitTime = 500
26
30
27
31
type EmptyObject = Record < string , never >
28
32
@@ -160,7 +164,6 @@ function SearchResult({
160
164
query : string
161
165
} ) {
162
166
let id = useId ( )
163
- let pathname = usePathname ( )
164
167
165
168
let sectionTitle = flatNavigation . find ( ( section ) =>
166
169
section . links ?. find ( ( link ) => link . href === result . url . split ( '#' ) [ 0 ] ) ,
@@ -267,6 +270,12 @@ const SearchInput = forwardRef<
267
270
autocompleteState . status === 'stalled' ? 'pr-11' : 'pr-4' ,
268
271
) }
269
272
{ ...inputProps }
273
+ onKeyUp = { ( ) => {
274
+ clearTimeout ( timer )
275
+ timer = setTimeout ( ( ) => {
276
+ track ( 'search' , { searchQuery : inputProps . value } )
277
+ } , waitTime )
278
+ } }
270
279
onKeyDown = { ( event ) => {
271
280
if (
272
281
event . key === 'Escape' &&
You can’t perform that action at this time.
0 commit comments