From 67c4fd64bedce39a2456440ada3297465f2165c9 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 27 Jul 2023 15:13:27 -0600 Subject: [PATCH 1/3] feat(sql-editor): ai telemetry --- .../interfaces/SQLEditor/SQLEditor.tsx | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx index c54bfff9e4a..2e843c165c8 100644 --- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx +++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx @@ -1,4 +1,4 @@ -import { useParams } from 'common' +import { useParams, useTelemetryProps } from 'common' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog' import { useSqlEditMutation } from 'data/ai/sql-edit-mutation' @@ -19,6 +19,7 @@ import useLatest from 'hooks/misc/useLatest' import { IS_PLATFORM } from 'lib/constants' import { uuidv4 } from 'lib/helpers' import { useProfile } from 'lib/profile' +import Telemetry from 'lib/telemetry' import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import { @@ -123,6 +124,7 @@ const SQLEditor = () => { const { ui } = useStore() const { ref, id } = useParams() const router = useRouter() + const telemetryProps = useTelemetryProps() const { profile } = useProfile() const { project } = useProjectContext() const snap = useSqlEditorStateSnapshot() @@ -299,6 +301,16 @@ const SQLEditor = () => { ]) } + Telemetry.sendEvent( + { + category: 'sql_editor', + action: 'ai_suggestion_accept', + label: debugSolution ? 'debug_snippet' : 'edit_snippet', + }, + telemetryProps, + router + ) + setAiInput('') setSelectedDiffType(DiffType.Modification) setDebugSolution(undefined) @@ -309,15 +321,25 @@ const SQLEditor = () => { } finally { setIsAcceptDiffLoading(false) } - }, [sqlDiff, selectedDiffType, handleNewQuery, titleSql]) + }, [sqlDiff, selectedDiffType, handleNewQuery, titleSql, debugSolution, telemetryProps, router]) const discardAiHandler = useCallback(() => { + Telemetry.sendEvent( + { + category: 'sql_editor', + action: 'ai_suggestion_reject', + label: debugSolution ? 'debug_snippet' : 'edit_snippet', + }, + telemetryProps, + router + ) + setDebugSolution(undefined) setSqlDiff(undefined) setTimeout(() => { inputRef.current?.focus() }, 0) - }, []) + }, [debugSolution, telemetryProps, router]) useEffect(() => { const handler = (e: KeyboardEvent) => { From 0e55ffab532bf9b792974fabf4c8cfc0813db307 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 31 Jul 2023 08:49:00 -0500 Subject: [PATCH 2/3] fix(sql-editor): rename telemetry action to past tense Co-authored-by: Pamela Chia --- studio/components/interfaces/SQLEditor/SQLEditor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx index 2e843c165c8..c2b70306426 100644 --- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx +++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx @@ -304,7 +304,7 @@ const SQLEditor = () => { Telemetry.sendEvent( { category: 'sql_editor', - action: 'ai_suggestion_accept', + action: 'ai_suggestion_accepted', label: debugSolution ? 'debug_snippet' : 'edit_snippet', }, telemetryProps, @@ -327,7 +327,7 @@ const SQLEditor = () => { Telemetry.sendEvent( { category: 'sql_editor', - action: 'ai_suggestion_reject', + action: 'ai_suggestion_rejected', label: debugSolution ? 'debug_snippet' : 'edit_snippet', }, telemetryProps, From f6240a2db8d4d3484b2fa2caeb3da15d1f92f9b5 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 31 Jul 2023 15:04:55 -0500 Subject: [PATCH 3/3] feat(sql-editor): telemetry for ai suggestion create events --- .../interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx index 9a35c2b366a..7542641a3ce 100644 --- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx +++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx @@ -182,6 +182,16 @@ const SQLTemplates = observer(() => { }) await handleNewQuery(formattedSql, title) + + Telemetry.sendEvent( + { + category: 'sql_editor', + action: 'ai_suggestion_created', + label: 'create_snippet', + }, + telemetryProps, + router + ) } catch (error: unknown) { if (isError(error)) { ui.setNotification({