@@ -7,7 +7,7 @@ import { useModalState } from "../../utils/hooks/modal-context";
77
88export const FollowupQueries = ( ) => {
99 const { props, trieveSDK, fingerprint } = useModalState ( ) ;
10- const { isDoneReading, askQuestion } = useChatState ( ) ;
10+ const { isDoneReading, askQuestion, messages } = useChatState ( ) ;
1111 const { suggestedQuestions, isLoadingSuggestedQueries } =
1212 useFollowupQuestions ( ) ;
1313 const [ parent ] = useAutoAnimate ( ) ;
@@ -17,40 +17,36 @@ export const FollowupQueries = () => {
1717 }
1818
1919 const handleFollowupQuery = async ( q : string ) => {
20- const lastMessage = JSON . parse (
21- window . localStorage . getItem ( "lastMessage" ) ?? "{}" ,
22- ) ;
23-
24- const requestId =
25- Object . keys ( lastMessage ) [ 0 ] || "00000000-0000-0000-0000-000000000000" ;
26-
27- await trieveSDK . sendAnalyticsEvent ( {
28- event_name : `site-followup_query` ,
29- event_type : "click" ,
30- user_id : fingerprint ,
31- location : window . location . href ,
32- metadata : {
33- followup_query : q ,
34- component_props : props ,
35- } ,
36- request : {
37- request_id : requestId ,
38- request_type : "rag" ,
39- } ,
40- } ) ;
20+ const requestId = messages [ messages . length - 1 ] . queryId ;
4121
22+ if ( requestId ) {
23+ await trieveSDK . sendAnalyticsEvent ( {
24+ event_name : `site-followup_query` ,
25+ event_type : "click" ,
26+ user_id : fingerprint ,
27+ location : window . location . href ,
28+ metadata : {
29+ followup_query : q ,
30+ component_props : props ,
31+ } ,
32+ request : {
33+ request_id : requestId ,
34+ request_type : "rag" ,
35+ } ,
36+ } ) ;
37+ } ;
4238 askQuestion ( q ) ;
43- } ;
39+
40+ }
4441
4542 return (
4643 < div ref = { parent } className = "followup-questions" >
4744 { suggestedQuestions ?. map ( ( q ) => (
4845 < button
4946 onClick = { ( ) => handleFollowupQuery ( q ) }
5047 key = { q }
51- className = { `followup-question ${
52- isLoadingSuggestedQueries ? "loading" : ""
53- } `}
48+ className = { `followup-question ${ isLoadingSuggestedQueries ? "loading" : ""
49+ } `}
5450 >
5551 < SparklesIcon className = "followup-icon" />
5652 { q }
0 commit comments