@@ -3,6 +3,8 @@ import { useState, useEffect, useRef, useCallback } from 'react';
33import { useRouter } from 'next/navigation' ;
44import { docsConfig , type LibraryId } from '../../lib/docs-config' ;
55import { tokens } from '@ngaf/design-tokens' ;
6+ import { analyticsEvents } from '../../lib/analytics/events' ;
7+ import { track } from '../../lib/analytics/client' ;
68
79interface SearchablePage {
810 title : string ;
@@ -60,6 +62,13 @@ export function DocsSearch({ library }: { library?: LibraryId }) {
6062 } , [ open ] ) ;
6163
6264 const navigate = ( page : SearchablePage ) => {
65+ track ( analyticsEvents . docsSearchResultClick , {
66+ surface : 'docs' ,
67+ destination_url : `/docs/${ page . library } /${ page . section } /${ page . slug } ` ,
68+ library : page . library === 'agent' || page . library === 'render' || page . library === 'chat' ? page . library : 'unknown' ,
69+ query_length : query . length ,
70+ result_count : results . length ,
71+ } ) ;
6372 router . push ( `/docs/${ page . library } /${ page . section } /${ page . slug } ` ) ;
6473 setOpen ( false ) ;
6574 } ;
@@ -95,7 +104,17 @@ export function DocsSearch({ library }: { library?: LibraryId }) {
95104 < input
96105 ref = { inputRef }
97106 value = { query }
98- onChange = { ( e ) => { setQuery ( e . target . value ) ; setSelected ( 0 ) ; } }
107+ onChange = { ( e ) => {
108+ const nextQuery = e . target . value ;
109+ setQuery ( nextQuery ) ;
110+ setSelected ( 0 ) ;
111+ if ( nextQuery . length === 1 ) {
112+ track ( analyticsEvents . docsSearchSubmit , {
113+ surface : 'docs' ,
114+ library : library === 'agent' || library === 'render' || library === 'chat' ? library : 'unknown' ,
115+ } ) ;
116+ }
117+ } }
99118 onKeyDown = { handleInputKeyDown }
100119 placeholder = "Search documentation..."
101120 style = { {
0 commit comments