Skip to content

Commit 25dc1ef

Browse files
awaseempamelachia
andauthored
Analytics: Update tracking for Advisor (supabase#40629)
* remove resolved events * Remove advisor_resolved event tracking * updated linting * updated events to be cleaner * refactored types * refactor(telemetry): rename advisor click telemetry to assistant button click --------- Co-authored-by: Pamela Chia <[email protected]>
1 parent cc1442d commit 25dc1ef

File tree

5 files changed

+144
-120
lines changed

5 files changed

+144
-120
lines changed

apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { createLintSummaryPrompt } from 'components/interfaces/Linter/Linter.uti
77
import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
88
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
99
import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'
10-
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
11-
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
10+
import { useTrack } from 'lib/telemetry/track'
1211
import { useAdvisorStateSnapshot } from 'state/advisor-state'
1312
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
1413
import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
@@ -26,9 +25,8 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
2625
enabled: !showEmptyState,
2726
}
2827
)
28+
const track = useTrack()
2929
const snap = useAiAssistantStateSnapshot()
30-
const { mutate: sendEvent } = useSendEventMutation()
31-
const { data: organization } = useSelectedOrganizationQuery()
3230
const { openSidebar } = useSidebarManagerSnapshot()
3331
const { setSelectedItem } = useAdvisorStateSnapshot()
3432

@@ -51,40 +49,25 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
5149

5250
const handleAskAssistant = useCallback(() => {
5351
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
54-
if (projectRef && organization?.slug) {
55-
sendEvent({
56-
action: 'home_advisor_ask_assistant_clicked',
57-
properties: {
58-
issues_count: totalErrors,
59-
},
60-
groups: {
61-
project: projectRef,
62-
organization: organization.slug,
63-
},
64-
})
65-
}
66-
}, [sendEvent, openSidebar, projectRef, organization, totalErrors])
52+
track('advisor_assistant_button_clicked', {
53+
origin: 'homepage',
54+
issuesCount: totalErrors,
55+
})
56+
}, [track, openSidebar, totalErrors])
6757

6858
const handleCardClick = useCallback(
6959
(lint: Lint) => {
7060
setSelectedItem(lint.cache_key, 'lint')
7161
openSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
72-
if (projectRef && organization?.slug) {
73-
sendEvent({
74-
action: 'home_advisor_issue_card_clicked',
75-
properties: {
76-
issue_category: lint.categories[0] || 'UNKNOWN',
77-
issue_name: lint.name,
78-
issues_count: totalErrors,
79-
},
80-
groups: {
81-
project: projectRef,
82-
organization: organization.slug,
83-
},
84-
})
85-
}
62+
track('advisor_detail_opened', {
63+
origin: 'homepage',
64+
advisorSource: 'lint',
65+
advisorCategory: lint.categories[0],
66+
advisorType: lint.name,
67+
advisorLevel: lint.level,
68+
})
8669
},
87-
[sendEvent, setSelectedItem, openSidebar, projectRef, organization, totalErrors]
70+
[track, setSelectedItem, openSidebar]
8871
)
8972

9073
if (showEmptyState) {
@@ -142,19 +125,12 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
142125
name: 'Summarize lint',
143126
initialInput: createLintSummaryPrompt(lint),
144127
})
145-
if (projectRef && organization?.slug) {
146-
sendEvent({
147-
action: 'home_advisor_fix_issue_clicked',
148-
properties: {
149-
issue_category: lint.categories[0] || 'UNKNOWN',
150-
issue_name: lint.name,
151-
},
152-
groups: {
153-
project: projectRef,
154-
organization: organization.slug,
155-
},
156-
})
157-
}
128+
track('advisor_assistant_button_clicked', {
129+
origin: 'homepage',
130+
advisorCategory: lint.categories[0],
131+
advisorType: lint.name,
132+
advisorLevel: lint.level,
133+
})
158134
}}
159135
tooltip={{
160136
content: { side: 'bottom', text: 'Help me fix this issue' },

apps/studio/components/interfaces/Linter/LintDetail.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ReactMarkdown from 'react-markdown'
44
import { createLintSummaryPrompt, lintInfoMap } from 'components/interfaces/Linter/Linter.utils'
55
import { Lint } from 'data/lint/lint-query'
66
import { DOCS_URL } from 'lib/constants'
7+
import { useTrack } from 'lib/telemetry/track'
78
import { ExternalLink } from 'lucide-react'
89
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
910
import { AiIconAnimation, Button } from 'ui'
@@ -18,9 +19,26 @@ interface LintDetailProps {
1819
}
1920

2021
const LintDetail = ({ lint, projectRef, onAskAssistant }: LintDetailProps) => {
22+
const track = useTrack()
2123
const snap = useAiAssistantStateSnapshot()
2224
const { openSidebar } = useSidebarManagerSnapshot()
2325

26+
const handleAskAssistant = () => {
27+
track('advisor_assistant_button_clicked', {
28+
origin: 'lint_detail',
29+
advisorCategory: lint.categories[0],
30+
advisorType: lint.name,
31+
advisorLevel: lint.level,
32+
})
33+
34+
onAskAssistant?.()
35+
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
36+
snap.newChat({
37+
name: 'Summarize lint',
38+
initialInput: createLintSummaryPrompt(lint),
39+
})
40+
}
41+
2442
return (
2543
<div>
2644
<h3 className="text-sm mb-2">Entity</h3>
@@ -42,14 +60,7 @@ const LintDetail = ({ lint, projectRef, onAskAssistant }: LintDetailProps) => {
4260
<div className="flex items-center gap-2">
4361
<Button
4462
icon={<AiIconAnimation className="scale-75 w-3 h-3" />}
45-
onClick={() => {
46-
onAskAssistant?.()
47-
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
48-
snap.newChat({
49-
name: 'Summarize lint',
50-
initialInput: createLintSummaryPrompt(lint),
51-
})
52-
}}
63+
onClick={handleAskAssistant}
5364
>
5465
Ask Assistant
5566
</Button>

apps/studio/components/interfaces/Linter/LinterDataGrid.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { X } from 'lucide-react'
2-
import { useRef, useState } from 'react'
2+
import { useRef } from 'react'
33
import DataGrid, { Column, DataGridHandle, Row } from 'react-data-grid'
44
import ReactMarkdown from 'react-markdown'
55

@@ -13,6 +13,7 @@ import {
1313
} from 'components/interfaces/Linter/Linter.utils'
1414
import { Lint } from 'data/lint/lint-query'
1515
import { useRouter } from 'next/router'
16+
import { useTrack } from 'lib/telemetry/track'
1617
import { Button, ResizableHandle, ResizablePanel, ResizablePanelGroup, cn } from 'ui'
1718
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
1819
import { EntityTypeIcon } from './Linter.utils'
@@ -34,6 +35,7 @@ const LinterDataGrid = ({
3435
const gridRef = useRef<DataGridHandle>(null)
3536
const { ref } = useParams()
3637
const router = useRouter()
38+
const track = useTrack()
3739

3840
const lintCols = [
3941
{
@@ -148,6 +150,14 @@ const LinterDataGrid = ({
148150
gridRef.current?.scrollToCell({ idx: 0, rowIdx: idx })
149151
const { id, ...rest } = router.query
150152
router.push({ ...router, query: { ...rest, id: props.row.cache_key } })
153+
154+
track('advisor_detail_opened', {
155+
origin: 'advisors_page',
156+
advisorSource: 'lint',
157+
advisorCategory: props.row.categories[0],
158+
advisorType: props.row.name,
159+
advisorLevel: props.row.level,
160+
})
151161
}
152162
}}
153163
/>

apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useNotificationsV2UpdateMutation } from 'data/notifications/notificatio
1212
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
1313
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
1414
import { IS_PLATFORM } from 'lib/constants'
15+
import { useTrack } from 'lib/telemetry/track'
1516
import { AdvisorSeverity, AdvisorTab, useAdvisorStateSnapshot } from 'state/advisor-state'
1617
import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
1718
import { AdvisorDetail } from './AdvisorDetail'
@@ -49,6 +50,7 @@ const notificationPriorityToSeverity = (priority: string | null | undefined): Ad
4950
}
5051

5152
export const AdvisorPanel = () => {
53+
const track = useTrack()
5254
const {
5355
activeTab,
5456
severityFilters,
@@ -250,12 +252,28 @@ export const AdvisorPanel = () => {
250252

251253
const handleItemClick = (item: AdvisorItem) => {
252254
setSelectedItem(item.id, item.source)
255+
253256
if (item.source === 'notification') {
254257
const notification = item.original as Notification
255258
if (notification.status === 'new' && !markedRead.current.includes(notification.id)) {
256259
markedRead.current.push(notification.id)
257260
}
258261
}
262+
263+
const advisorCategory =
264+
item.source === 'lint' && 'categories' in item.original
265+
? item.original.categories[0]
266+
: undefined
267+
const advisorLevel =
268+
item.source === 'lint' && 'level' in item.original ? item.original.level : undefined
269+
270+
track('advisor_detail_opened', {
271+
origin: 'advisor_panel',
272+
advisorCategory,
273+
advisorSource: item.source,
274+
advisorType: item.original.name,
275+
advisorLevel,
276+
})
259277
}
260278

261279
const handleUpdateNotificationStatus = (id: string, status: 'archived' | 'seen') => {

0 commit comments

Comments
 (0)