@@ -5,6 +5,7 @@ import remarkGfm from "remark-gfm";
55import { fetchEventSource } from "@microsoft/fetch-event-source" ;
66import { Ring } from "ldrs/react" ;
77import { MdOutlineThumbUp , MdOutlineThumbDown } from "react-icons/md" ;
8+ import { track } from "~/util/zaraz" ;
89import "ldrs/react/Ring.css" ;
910
1011type Messages = {
@@ -31,6 +32,29 @@ async function sendCSATFeedback(queryId: string, positive: boolean) {
3132 }
3233}
3334
35+ function TrackedLink ( {
36+ href,
37+ children,
38+ } : {
39+ href ?: string ;
40+ children ?: React . ReactNode ;
41+ } ) {
42+ return (
43+ < a
44+ href = { href }
45+ target = "_blank"
46+ onClick = { ( ) =>
47+ track ( "click chat link" , {
48+ value : children ?. toString ( ) ?? "" ,
49+ href,
50+ } )
51+ }
52+ >
53+ { children }
54+ </ a >
55+ ) ;
56+ }
57+
3458function Messages ( {
3559 messages,
3660 loading,
@@ -47,6 +71,9 @@ function Messages({
4771 } ;
4872
4973 const handleFeedback = async ( queryId : string , positive : boolean ) => {
74+ track ( "submit chat feedback" , {
75+ value : positive . toString ( ) ,
76+ } ) ;
5077 await sendCSATFeedback ( queryId , positive ) ;
5178 setFeedbackGiven ( ( prev ) => new Set ( prev ) . add ( queryId ) ) ;
5279 } ;
@@ -60,7 +87,12 @@ function Messages({
6087 < div
6188 className = { `${ classes . base } ${ message . role === "user" ? classes . user : classes . assistant } ` }
6289 >
63- < Markdown remarkPlugins = { [ remarkGfm , remarkBreaks ] } >
90+ < Markdown
91+ remarkPlugins = { [ remarkGfm , remarkBreaks ] }
92+ components = { {
93+ a : TrackedLink ,
94+ } }
95+ >
6496 { message . content }
6597 </ Markdown >
6698 { message . sources && (
@@ -71,10 +103,10 @@ function Messages({
71103 </ p >
72104 < ul >
73105 { message . sources . map ( ( source ) => (
74- < li >
75- < a href = { source . file_path } target = "_blank" >
106+ < li key = { source . file_path } >
107+ < TrackedLink href = { source . file_path } >
76108 { source . title }
77- </ a >
109+ </ TrackedLink >
78110 </ li >
79111 ) ) }
80112 </ ul >
@@ -124,6 +156,10 @@ export default function SupportAI() {
124156 const [ messages , setMessages ] = useState < Messages > ( [ ] ) ;
125157
126158 async function handleSubmit ( ) {
159+ track ( "submit chat" , {
160+ value : question ,
161+ } ) ;
162+
127163 setLoading ( true ) ;
128164 setMessages ( ( messages ) => [
129165 ...messages ,
0 commit comments