diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/AIButton.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/AIButton.tsx index 45bd1ed4..0ce42673 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/AIButton.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/AIButton.tsx @@ -16,6 +16,7 @@ import { useTranslation } from 'react-i18next'; import { isAPIError } from '@/api'; import { Box, Icon } from '@/components'; import { useDocOptions, useDocStore } from '@/docs/doc-management/'; +import { useAnalytics } from '@/libs'; import { AITransformActions, @@ -217,22 +218,44 @@ const AIMenuItemTransform = ({ children, icon, }: PropsWithChildren) => { + const { trackEvent } = useAnalytics(); const { mutateAsync: requestAI, isPending } = useDocAITransform(); const editor = useBlockNoteEditor(); const requestAIAction = async (selectedBlocks: Block[]) => { const text = await editor.blocksToMarkdownLossy(selectedBlocks); + const requestStartTime = performance.now(); const responseAI = await requestAI({ text, action, docId, }); + const requestDuration = performance.now() - requestStartTime; + + const eventProperties = { + eventName: 'requestAIAction', + action: action, + docId: docId, + requestLength: text.length, + numberBlocks: selectedBlocks.length, + requestDuration: requestDuration, + }; if (!responseAI?.answer) { + trackEvent({ + ...eventProperties, + status: 'error', + }); throw new Error('No response from AI'); } + trackEvent({ + ...eventProperties, + status: 'success', + responseLength: String(responseAI.answer), + }); + const markdown = await editor.tryParseMarkdownToBlocks(responseAI.answer); editor.replaceBlocks(selectedBlocks, markdown); };