The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Analytics: Update tracking for Advisor (#40629)
Ali Waseem25dc1efb9f40
diff --git a/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx b/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsxindex ffcc9d52752..fcd89f18fc0 100644--- a/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx+++ b/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx@@ -7,8 +7,7 @@ import { createLintSummaryPrompt } from 'components/interfaces/Linter/Linter.utiimport { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'-import { useSendEventMutation } from 'data/telemetry/send-event-mutation'-import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'+import { useTrack } from 'lib/telemetry/track'import { useAdvisorStateSnapshot } from 'state/advisor-state'import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'@@ -26,9 +25,8 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boenabled: !showEmptyState,})+ const track = useTrack()const snap = useAiAssistantStateSnapshot()- const { mutate: sendEvent } = useSendEventMutation()- const { data: organization } = useSelectedOrganizationQuery()const { openSidebar } = useSidebarManagerSnapshot()const { setSelectedItem } = useAdvisorStateSnapshot()@@ -51,40 +49,25 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boconst handleAskAssistant = useCallback(() => {openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)- if (projectRef && organization?.slug) {- sendEvent({- action: 'home_advisor_ask_assistant_clicked',- properties: {- issues_count: totalErrors,- },- groups: {- project: projectRef,- organization: organization.slug,- },- })- }- }, [sendEvent, openSidebar, projectRef, organization, totalErrors])+ track('advisor_assistant_button_clicked', {+ origin: 'homepage',+ issuesCount: totalErrors,+ })+ }, [track, openSidebar, totalErrors])const handleCardClick = useCallback((lint: Lint) => {setSelectedItem(lint.cache_key, 'lint')openSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)- if (projectRef && organization?.slug) {- sendEvent({- action: 'home_advisor_issue_card_clicked',- properties: {- issue_category: lint.categories[0] || 'UNKNOWN',- issue_name: lint.name,- issues_count: totalErrors,- },- groups: {- project: projectRef,- organization: organization.slug,- },- })- }+ track('advisor_detail_opened', {+ origin: 'homepage',+ advisorSource: 'lint',+ advisorCategory: lint.categories[0],+ advisorType: lint.name,+ advisorLevel: lint.level,+ })},- [sendEvent, setSelectedItem, openSidebar, projectRef, organization, totalErrors]+ [track, setSelectedItem, openSidebar])if (showEmptyState) {@@ -142,19 +125,12 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boname: 'Summarize lint',initialInput: createLintSummaryPrompt(lint),})- if (projectRef && organization?.slug) {- sendEvent({- action: 'home_advisor_fix_issue_clicked',- properties: {- issue_category: lint.categories[0] || 'UNKNOWN',- issue_name: lint.name,- },- groups: {- project: projectRef,- organization: organization.slug,- },- })- }+ track('advisor_assistant_button_clicked', {+ origin: 'homepage',+ advisorCategory: lint.categories[0],+ advisorType: lint.name,+ advisorLevel: lint.level,+ })}}tooltip={{content: { side: 'bottom', text: 'Help me fix this issue' },diff --git a/apps/studio/components/interfaces/Linter/LintDetail.tsx b/apps/studio/components/interfaces/Linter/LintDetail.tsxindex f5c04d4d806..334353bd703 100644--- a/apps/studio/components/interfaces/Linter/LintDetail.tsx+++ b/apps/studio/components/interfaces/Linter/LintDetail.tsx@@ -4,6 +4,7 @@ import ReactMarkdown from 'react-markdown'import { createLintSummaryPrompt, lintInfoMap } from 'components/interfaces/Linter/Linter.utils'import { Lint } from 'data/lint/lint-query'import { DOCS_URL } from 'lib/constants'+import { useTrack } from 'lib/telemetry/track'import { ExternalLink } from 'lucide-react'import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'import { AiIconAnimation, Button } from 'ui'@@ -18,9 +19,26 @@ interface LintDetailProps {}const LintDetail = ({ lint, projectRef, onAskAssistant }: LintDetailProps) => {+ const track = useTrack()const snap = useAiAssistantStateSnapshot()const { openSidebar } = useSidebarManagerSnapshot()+ const handleAskAssistant = () => {+ track('advisor_assistant_button_clicked', {+ origin: 'lint_detail',+ advisorCategory: lint.categories[0],+ advisorType: lint.name,+ advisorLevel: lint.level,+ })++ onAskAssistant?.()+ openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)+ snap.newChat({+ name: 'Summarize lint',+ initialInput: createLintSummaryPrompt(lint),+ })+ }+return (<div><h3 className="text-sm mb-2">Entity</h3>@@ -42,14 +60,7 @@ const LintDetail = ({ lint, projectRef, onAskAssistant }: LintDetailProps) => {<div className="flex items-center gap-2"><Buttonicon={<AiIconAnimation className="scale-75 w-3 h-3" />}- onClick={() => {- onAskAssistant?.()- openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)- snap.newChat({- name: 'Summarize lint',- initialInput: createLintSummaryPrompt(lint),- })- }}+ onClick={handleAskAssistant}>Ask Assistant</Button>diff --git a/apps/studio/components/interfaces/Linter/LinterDataGrid.tsx b/apps/studio/components/interfaces/Linter/LinterDataGrid.tsxindex ae9bcad47b1..07817830d7e 100644--- a/apps/studio/components/interfaces/Linter/LinterDataGrid.tsx+++ b/apps/studio/components/interfaces/Linter/LinterDataGrid.tsx@@ -1,5 +1,5 @@import { X } from 'lucide-react'-import { useRef, useState } from 'react'+import { useRef } from 'react'import DataGrid, { Column, DataGridHandle, Row } from 'react-data-grid'import ReactMarkdown from 'react-markdown'@@ -13,6 +13,7 @@ import {} from 'components/interfaces/Linter/Linter.utils'import { Lint } from 'data/lint/lint-query'import { useRouter } from 'next/router'+import { useTrack } from 'lib/telemetry/track'import { Button, ResizableHandle, ResizablePanel, ResizablePanelGroup, cn } from 'ui'import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'import { EntityTypeIcon } from './Linter.utils'@@ -34,6 +35,7 @@ const LinterDataGrid = ({const gridRef = useRef<DataGridHandle>(null)const { ref } = useParams()const router = useRouter()+ const track = useTrack()const lintCols = [{@@ -148,6 +150,14 @@ const LinterDataGrid = ({gridRef.current?.scrollToCell({ idx: 0, rowIdx: idx })const { id, ...rest } = router.queryrouter.push({ ...router, query: { ...rest, id: props.row.cache_key } })++ track('advisor_detail_opened', {+ origin: 'advisors_page',+ advisorSource: 'lint',+ advisorCategory: props.row.categories[0],+ advisorType: props.row.name,+ advisorLevel: props.row.level,+ })}}}/>diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsxindex cd57b2400be..083e50217fb 100644--- a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx@@ -12,6 +12,7 @@ import { useNotificationsV2UpdateMutation } from 'data/notifications/notificatioimport { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { IS_PLATFORM } from 'lib/constants'+import { useTrack } from 'lib/telemetry/track'import { AdvisorSeverity, AdvisorTab, useAdvisorStateSnapshot } from 'state/advisor-state'import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'import { AdvisorDetail } from './AdvisorDetail'@@ -49,6 +50,7 @@ const notificationPriorityToSeverity = (priority: string | null | undefined): Ad}export const AdvisorPanel = () => {+ const track = useTrack()const {activeTab,severityFilters,@@ -250,12 +252,28 @@ export const AdvisorPanel = () => {const handleItemClick = (item: AdvisorItem) => {setSelectedItem(item.id, item.source)+if (item.source === 'notification') {const notification = item.original as Notificationif (notification.status === 'new' && !markedRead.current.includes(notification.id)) {markedRead.current.push(notification.id)}}++ const advisorCategory =+ item.source === 'lint' && 'categories' in item.original+ ? item.original.categories[0]+ : undefined+ const advisorLevel =+ item.source === 'lint' && 'level' in item.original ? item.original.level : undefined++ track('advisor_detail_opened', {+ origin: 'advisor_panel',+ advisorCategory,+ advisorSource: item.source,+ advisorType: item.original.name,+ advisorLevel,+ })}const handleUpdateNotificationStatus = (id: string, status: 'archived' | 'seen') => {diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.tsindex 767ce07df87..c364c5230f9 100644--- a/packages/common/telemetry-constants.ts+++ b/packages/common/telemetry-constants.ts@@ -1616,24 +1616,6 @@ export interface HomeActivityStatClickedEvent {groups: TelemetryGroups}-/**- * User clicked the main Ask Assistant button in the Advisor section of HomeV2.- *- * @group Events- * @source studio- * @page /project/{ref}- */-export interface HomeAdvisorAskAssistantClickedEvent {- action: 'home_advisor_ask_assistant_clicked'- properties: {- /**- * Number of issues found by the advisor- */- issues_count: number- }- groups: TelemetryGroups-}-/*** User was exposed to the realtime experiment (shown or not shown the Enable Realtime button).*@@ -1660,51 +1642,6 @@ export interface RealtimeExperimentExposedEvent {groups: TelemetryGroups}-/**- * User clicked on an issue card in the Advisor section of HomeV2.- *- * @group Events- * @source studio- * @page /project/{ref}- */-export interface HomeAdvisorIssueCardClickedEvent {- action: 'home_advisor_issue_card_clicked'- properties: {- /**- * Category of the issue (SECURITY or PERFORMANCE)- */- issue_category: string- /**- * Name/key of the lint issue- */- issue_name: string- issues_count: number- }- groups: TelemetryGroups-}--/**- * User clicked the Fix Issue button on an advisor card in HomeV2.- *- * @group Events- * @source studio- * @page /project/{ref}- */-export interface HomeAdvisorFixIssueClickedEvent {- action: 'home_advisor_fix_issue_clicked'- properties: {- /**- * Category of the issue (SECURITY or PERFORMANCE)- */- issue_category: string- /**- * Name/key of the lint issue- */- issue_name: string- }- groups: TelemetryGroups-}-/*** User clicked on a service title in Project Usage section of HomeV2.*@@ -2349,6 +2286,79 @@ export interface LogDrainConfirmButtonSubmittedEvent {groups: TelemetryGroups}+type AdvisorCategory = 'PERFORMANCE' | 'SECURITY'+type AdvisorLevel = 'ERROR' | 'WARN' | 'INFO'++/**+ * User opened an advisor detail page to view a specific advisor (lint or notification).+ * This tracks when users engage with advisor recommendations.+ *+ * @group Events+ * @source studio+ * @page /dashboard/project/{ref}/advisors/security or home page or advisor panel sidebar+ */+export interface AdvisorDetailOpenedEvent {+ action: 'advisor_detail_opened'+ properties: {+ /**+ * Where the advisor was viewed from+ */+ origin: 'homepage' | 'advisor_panel' | 'advisors_page'+ /**+ * Source of the advisor+ */+ advisorSource: 'lint' | 'notification'+ /**+ * Category of the advisor (SECURITY or PERFORMANCE)+ */+ advisorCategory?: AdvisorCategory+ /**+ * Specific advisor type/name, e.g. missing_index, no_rls_policy+ */+ advisorType?: string+ /**+ * Severity level of the advisor (only for lints)+ */+ advisorLevel?: AdvisorLevel+ }+ groups: TelemetryGroups+}++/**+ * User clicked the Assistant button to get AI help with an advisor issue.+ * This opens the AI Assistant sidebar with a pre-filled prompt about the issue.+ *+ * @group Events+ * @source studio+ * @page /dashboard/project/{ref} (homepage), /dashboard/project/{ref}/advisors/security or /dashboard/project/{ref}/advisors/performance (lint detail panel)+ */+export interface AdvisorAssistantButtonClickedEvent {+ action: 'advisor_assistant_button_clicked'+ properties: {+ /**+ * Where the button was clicked+ */+ origin: 'homepage' | 'lint_detail'+ /**+ * Category of the advisor (SECURITY or PERFORMANCE)+ */+ advisorCategory?: AdvisorCategory+ /**+ * Specific advisor type/name+ */+ advisorType?: string+ /**+ * Severity level of the advisor (only for lints)+ */+ advisorLevel?: AdvisorLevel+ /**+ * Number of issues found (only included when origin is 'homepage')+ */+ issuesCount?: number+ }+ groups: TelemetryGroups+}+/*** @hidden*/@@ -2451,9 +2461,6 @@ export type TelemetryEvent =| HomeGettingStartedClosedEvent| HomeSectionRowsMovedEvent| HomeActivityStatClickedEvent- | HomeAdvisorAskAssistantClickedEvent- | HomeAdvisorIssueCardClickedEvent- | HomeAdvisorFixIssueClickedEvent| RealtimeExperimentExposedEvent| HomeProjectUsageServiceClickedEvent| HomeProjectUsageChartClickedEvent@@ -2480,3 +2487,5 @@ export type TelemetryEvent =| SidebarOpenedEvent| LogDrainSaveButtonClickedEvent| LogDrainConfirmButtonSubmittedEvent+ | AdvisorDetailOpenedEvent+ | AdvisorAssistantButtonClickedEvent