@@ -83,6 +83,7 @@ import getDiscourseRelations, {
8383 DiscourseRelation ,
8484} from "~/utils/getDiscourseRelations" ;
8585import { AddReferencedNodeType } from "./canvas/DiscourseRelationShape/DiscourseRelationTool" ;
86+ import posthog from "posthog-js" ;
8687
8788const ExportProgress = ( { id } : { id : string } ) => {
8889 const [ progress , setProgress ] = useState ( 0 ) ;
@@ -154,6 +155,9 @@ const ExportDialog: ExportDialogComponent = ({
154155 useEffect ( ( ) => {
155156 setDialogOpen ( isOpen ) ;
156157 } , [ isOpen ] ) ;
158+
159+ // TODO: maybe add posthog capture here for isOpen
160+
157161 const [ dialogOpen , setDialogOpen ] = useState ( isOpen ) ;
158162 const exportTypes = useMemo (
159163 ( ) => getExportTypes ( { results, exportId, isExportDiscourseGraph } ) ,
@@ -651,6 +655,8 @@ const ExportDialog: ExportDialogComponent = ({
651655 let toastContent : React . ReactNode ;
652656 let uid = selectedPageUid ;
653657 const title = selectedPageTitle ;
658+ const isCanvasDestination = ! isSendToGraph && isCanvasPage ;
659+ const shouldCreatePage = ! isSendToGraph && ! isLiveBlock ( uid ) ;
654660
655661 if ( isSendToGraph ) {
656662 addToGraphOverView ( ) ;
@@ -687,6 +693,13 @@ const ExportDialog: ExportDialogComponent = ({
687693 ) ;
688694 }
689695
696+ posthog . capture ( "Results View: Send To Destination" , {
697+ destination : isSendToGraph ? "graph" : "page" ,
698+ isCanvasDestination,
699+ createdPage : shouldCreatePage ,
700+ resultCount : results . length ,
701+ } ) ;
702+
690703 renderToast ( {
691704 content : toastContent ,
692705 intent : "success" ,
@@ -735,10 +748,20 @@ const ExportDialog: ExportDialogComponent = ({
735748 if ( download ) {
736749 const blob = new Blob ( [ download ] , { type : "application/zip" } ) ;
737750 saveAs ( blob , `${ filename } .zip` ) ;
751+ posthog . capture ( "Export Dialog: Export Completed" , {
752+ exportType : "PDF" ,
753+ destination : activeExportDestination ,
754+ fileCount : files . length ,
755+ } ) ;
738756 }
739757 onClose ( ) ;
740758 } catch ( e ) {
741759 setError ( "Failed to export files." ) ;
760+ posthog . capture ( "Export Dialog: Export Failed" , {
761+ exportType : "PDF" ,
762+ destination : activeExportDestination ,
763+ error : ( e as Error ) . message ?? "unknown error" ,
764+ } ) ;
742765 }
743766 } ;
744767 const ExportPanel = (
@@ -838,6 +861,13 @@ const ExportDialog: ExportDialogComponent = ({
838861 setLoading ( true ) ;
839862 updateExportProgress ( { progress : 0 , id : exportId } ) ;
840863 setError ( "" ) ;
864+ posthog . capture ( "Export Dialog: Export Started" , {
865+ exportType : activeExportType ,
866+ destination : activeExportDestination ,
867+ includeDiscourseContext,
868+ resultCount : results . length ,
869+ isExportDiscourseGraph,
870+ } ) ;
841871 // eslint-disable-next-line @typescript-eslint/no-misused-promises
842872 setTimeout ( async ( ) => {
843873 try {
@@ -879,6 +909,11 @@ const ExportDialog: ExportDialogComponent = ({
879909 content : "Upload Success" ,
880910 intent : "success" ,
881911 } ) ;
912+ posthog . capture ( "Export Dialog: Export Completed" , {
913+ exportType : activeExportType ,
914+ destination : activeExportDestination ,
915+ fileCount : files . length ,
916+ } ) ;
882917 onClose ( ) ;
883918 }
884919 } catch ( error ) {
@@ -894,6 +929,11 @@ const ExportDialog: ExportDialogComponent = ({
894929 type : "text/plain;charset=utf-8" ,
895930 } ) ;
896931 saveAs ( blob , title ) ;
932+ posthog . capture ( "Export Dialog: Export Completed" , {
933+ exportType : activeExportType ,
934+ destination : activeExportDestination ,
935+ fileCount : files . length ,
936+ } ) ;
897937 onClose ( ) ;
898938 return ;
899939 }
@@ -906,12 +946,22 @@ const ExportDialog: ExportDialogComponent = ({
906946 ) ;
907947 void zip . generateAsync ( { type : "blob" } ) . then ( ( content ) => {
908948 saveAs ( content , `${ filename } .zip` ) ;
949+ posthog . capture ( "Export Dialog: Export Completed" , {
950+ exportType : activeExportType ,
951+ destination : activeExportDestination ,
952+ fileCount : files . length ,
953+ } ) ;
909954 onClose ( ) ;
910955 } ) ;
911956 } else {
912957 setError ( `Unsupported export type: ${ exportType } ` ) ;
913958 }
914959 } catch ( e ) {
960+ posthog . capture ( "Export Dialog: Export Failed" , {
961+ exportType : activeExportType ,
962+ destination : activeExportDestination ,
963+ error : ( e as Error ) . message ?? "unknown error" ,
964+ } ) ;
915965 internalError ( {
916966 error : e as Error ,
917967 type : "Export Dialog Failed" ,
@@ -1007,7 +1057,12 @@ const ExportDialog: ExportDialogComponent = ({
10071057 id = "export-tabs"
10081058 large = { true }
10091059 selectedTabId = { selectedTabId }
1010- onChange = { ( newTabId : string ) => setSelectedTabId ( newTabId ) }
1060+ onChange = { ( newTabId : string ) => {
1061+ setSelectedTabId ( newTabId ) ;
1062+ posthog . capture ( "Export Dialog: Tab Opened" , {
1063+ tabId : newTabId ,
1064+ } ) ;
1065+ } }
10111066 >
10121067 < Tab id = "sendto" title = "Send To" panel = { SendToPanel } />
10131068 < Tab id = "export" title = "Export" panel = { ExportPanel } />
0 commit comments