Skip to content

Commit 1530235

Browse files
committed
add tracking event to seach
1 parent 745cdfd commit 1530235

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/Search.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import { Dialog } from '@headlessui/react'
2222
import clsx from 'clsx'
2323
import { type Result } from '@/markdoc/search.mjs'
2424

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
2630

2731
type EmptyObject = Record<string, never>
2832

@@ -160,7 +164,6 @@ function SearchResult({
160164
query: string
161165
}) {
162166
let id = useId()
163-
let pathname = usePathname()
164167

165168
let sectionTitle = flatNavigation.find((section) =>
166169
section.links?.find((link) => link.href === result.url.split('#')[0]),
@@ -267,6 +270,12 @@ const SearchInput = forwardRef<
267270
autocompleteState.status === 'stalled' ? 'pr-11' : 'pr-4',
268271
)}
269272
{...inputProps}
273+
onKeyUp={() => {
274+
clearTimeout(timer)
275+
timer = setTimeout(() => {
276+
track('search', { searchQuery: inputProps.value })
277+
}, waitTime)
278+
}}
270279
onKeyDown={(event) => {
271280
if (
272281
event.key === 'Escape' &&

0 commit comments

Comments
 (0)