mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
📈(frontend) add tracking for AI actions usage and success rates
Implement analytics tracking on AI actions to collect insights on usage patterns and monitor error/success rates. Enables data-driven improvements. Temporary solution until backend implements more precise tracking for comprehensive AI feature analytics.
This commit is contained in:
parent
69006f0ef0
commit
3cfcdcf036
1 changed files with 23 additions and 0 deletions
|
|
@ -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<AIMenuItemTransform>) => {
|
||||
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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue