Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: add ai assistant event docs (#32394)

Pamela Chia35286ed46428
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index fd4d7194cfb..bd303330e38 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -421,7 +421,10 @@ export const SQLEditor = () => {
}
}
- sendEvent({ action: TelemetryActions.ASSISTANT_SUGGESTION_ACCEPTED })
+ sendEvent({
+ action: TelemetryActions.ASSISTANT_SQL_DIFF_HANDLER_EVALUATED,
+ properties: { handlerAccepted: true },
+ })
setSelectedDiffType(DiffType.Modification)
resetPrompt()
@@ -442,7 +445,10 @@ export const SQLEditor = () => {
])
const discardAiHandler = useCallback(() => {
- sendEvent({ action: TelemetryActions.ASSISTANT_SUGGESTION_REJECTED })
+ sendEvent({
+ action: TelemetryActions.ASSISTANT_SQL_DIFF_HANDLER_EVALUATED,
+ properties: { handlerAccepted: false },
+ })
resetPrompt()
closeDiff()
}, [closeDiff, resetPrompt, sendEvent])
diff --git a/apps/studio/components/ui/AIAssistantPanel/SqlSnippet.tsx b/apps/studio/components/ui/AIAssistantPanel/SqlSnippet.tsx
index 47b3d10a056..87701f56f12 100644
--- a/apps/studio/components/ui/AIAssistantPanel/SqlSnippet.tsx
+++ b/apps/studio/components/ui/AIAssistantPanel/SqlSnippet.tsx
@@ -213,7 +213,7 @@ export const SqlCard = ({
})
sendEvent({
- action: TelemetryActions.ASSISTANT_SUGGESTION_RAN,
+ action: TelemetryActions.ASSISTANT_SUGGESTION_RUN_QUERY_CLICKED,
properties: {
type: 'mutation',
category: identifyQueryType(sql) ?? 'unknown',
@@ -261,7 +261,13 @@ export const SqlCard = ({
icon={<Edit size={14} />}
onClick={() => {
handleEditInSQLEditor()
- sendEvent({ action: TelemetryActions.ASSISTANT_EDIT_SQL_CLICKED })
+ sendEvent({
+ action: TelemetryActions.ASSISTANT_EDIT_IN_SQL_EDITOR_CLICKED,
+ properties: {
+ isInSQLEditor,
+ isInNewSnippet,
+ },
+ })
}}
tooltip={{ content: { side: 'bottom', text: 'Edit in SQL Editor' } }}
/>
@@ -306,7 +312,7 @@ export const SqlCard = ({
handleExecute()
if (isReadOnlySelect(sql)) {
sendEvent({
- action: TelemetryActions.ASSISTANT_SUGGESTION_RAN,
+ action: TelemetryActions.ASSISTANT_SUGGESTION_RUN_QUERY_CLICKED,
properties: { type: 'select' },
})
}
diff --git a/apps/studio/data/telemetry/send-event-mutation.ts b/apps/studio/data/telemetry/send-event-mutation.ts
index 9ee61e52e9a..ed38f2d7a76 100644
--- a/apps/studio/data/telemetry/send-event-mutation.ts
+++ b/apps/studio/data/telemetry/send-event-mutation.ts
@@ -30,6 +30,11 @@ import {
RealtimeInspectorCopyMessageClickedEvent,
RealtimeInspectorFiltersAppliedEvent,
RealtimeInspectorDatabaseRoleUpdatedEvent,
+ AssistantPromptSubmittedEvent,
+ AssistantDebugSubmittedEvent,
+ AssistantSuggestionRunQueryClickedEvent,
+ AssistantSqlDiffHandlerEvaluatedEvent,
+ AssistantEditInSqlEditorClickedEvent,
} from 'lib/constants/telemetry'
import { useRouter } from 'next/router'
import type { ResponseError } from 'types'
@@ -59,6 +64,11 @@ export type SendEventVariables =
| SqlEditorResultDownloadCsvClickedEvent
| SqlEditorResultCopyMarkdownClickedEvent
| SqlEditorResultCopyJsonClickedEvent
+ | AssistantPromptSubmittedEvent
+ | AssistantDebugSubmittedEvent
+ | AssistantSuggestionRunQueryClickedEvent
+ | AssistantSqlDiffHandlerEvaluatedEvent
+ | AssistantEditInSqlEditorClickedEvent
// TODO remove this once all events are documented
| {
diff --git a/apps/studio/lib/constants/telemetry.ts b/apps/studio/lib/constants/telemetry.ts
index 8b9c691c1fe..4d636fe8abd 100644
--- a/apps/studio/lib/constants/telemetry.ts
+++ b/apps/studio/lib/constants/telemetry.ts
@@ -6,11 +6,9 @@ export enum TelemetryActions {
ASSISTANT_PROMPT_SUBMITTED = 'assistant_prompt_submitted',
ASSISTANT_DEBUG_SUBMITTED = 'assistant_debug_submitted',
- ASSISTANT_SUGGESTION_RAN = 'assistant_suggestion_ran',
- ASSISTANT_SUGGESTION_ACCEPTED = 'assistant_suggestion_accepted',
- ASSISTANT_SUGGESTION_REJECTED = 'assistant_suggestion_rejected',
- ASSISTANT_SUGGESTION_COPIED = 'assistant_suggestion_copied',
- ASSISTANT_EDIT_SQL_CLICKED = 'assistant_edit_sql_clicked',
+ ASSISTANT_SUGGESTION_RUN_QUERY_CLICKED = 'assistant_suggestion_run_query_clicked',
+ ASSISTANT_SQL_DIFF_HANDLER_EVALUATED = 'assistant_sql_diff_handler_evaluated',
+ ASSISTANT_EDIT_IN_SQL_EDITOR_CLICKED = 'assistant_edit_in_sql_editor_clicked',
CONNECTION_STRING_COPIED = 'connection_string_copied',
@@ -372,3 +370,74 @@ export interface SqlEditorResultCopyMarkdownClickedEvent {
export interface SqlEditorResultCopyJsonClickedEvent {
action: TelemetryActions.SQL_EDITOR_RESULT_COPY_JSON_CLICKED
}
+
+/**
+ * User submitted a prompt to the assistant sidebar.
+ *
+ * @group Events
+ * @source studio
+ */
+export interface AssistantPromptSubmittedEvent {
+ action: TelemetryActions.ASSISTANT_PROMPT_SUBMITTED
+}
+
+/**
+ * User submitted a debug request to the assistant sidebar or prompt submitted has Help me to debug.
+ *
+ * @group Events
+ * @source studio
+ */
+export interface AssistantDebugSubmittedEvent {
+ action: TelemetryActions.ASSISTANT_DEBUG_SUBMITTED
+}
+
+/**
+ * User clicked the run query button in the suggestion provided in the assistant sidebar.
+ *
+ * @group Events
+ * @source studio
+ */
+export interface AssistantSuggestionRunQueryClickedEvent {
+ action: TelemetryActions.ASSISTANT_SUGGESTION_RUN_QUERY_CLICKED
+ properties: {
+ /**
+ * The type of suggestion that was run by the user. Mutate or Select query types only.
+ */
+ queryType: string
+ category?: string
+ }
+}
+
+/**
+ * User accepted or rejected changes in sql ai diff handler. They can accept change by clicking accept button or typing shortcut (CMD+Enter) or reject by clicking reject button or typing shortcut (Esc). Handler only appears after clicking any dropdown option in Edit in Sql Editor in suggestion provided by the assistant. The dropdown options only appear in any page with 'sql' in url.
+ *
+ * @group Events
+ * @source studio
+ * @page /dashboard/project/{ref}/sql
+ */
+export interface AssistantSqlDiffHandlerEvaluatedEvent {
+ action: TelemetryActions.ASSISTANT_SQL_DIFF_HANDLER_EVALUATED
+ properties: {
+ /**
+ * Whether the user accepted or rejected the changes.
+ */
+ handlerAccepted: boolean
+ }
+}
+
+/**
+ * User clicked Edit in SQL Editor button in the assistant sidebar when user is in any page that does not have 'sql' in url or is in a new snippet.
+ *
+ * @group Events
+ * @source studio
+ */
+export interface AssistantEditInSqlEditorClickedEvent {
+ action: TelemetryActions.ASSISTANT_EDIT_IN_SQL_EDITOR_CLICKED
+ properties: {
+ /**
+ * Whether the user is in the SQL editor page or in a new snippet.
+ */
+ isInSQLEditor: boolean
+ isInNewSnippet: boolean
+ }
+}