Skip to content

Commit 0ed7aad

Browse files
authored
feat: add web console usage telemetry (#544)
* feat: add web console usage telemetry * catch unmocked requests * remove reset test * reset module for each test * restore mocks * lint errors & user agent polyfill on ci * no manual ua parsing * get endpoint console-event-config * submodule * add actions to store * promo view event * submodule * submodule * lint fix * more events * new events, change default models
1 parent 3d8bc46 commit 0ed7aad

59 files changed

Lines changed: 1678 additions & 34 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@styled-icons/remix-line": "10.46.0",
6363
"allotment": "^1.19.3",
6464
"animate.css": "3.7.2",
65+
"bowser": "^2.14.1",
6566
"compare-versions": "^5.0.1",
6667
"core-js": "^3.22.8",
6768
"date-fns": "4.1.0",
@@ -147,6 +148,7 @@
147148
"eslint-plugin-prettier": "^5.2.3",
148149
"eslint-plugin-react": "^7.37.5",
149150
"eslint-plugin-react-hooks": "^5.1.0",
151+
"fake-indexeddb": "^6.2.5",
150152
"globals": "^15.0.0",
151153
"husky": "^9.1.7",
152154
"jiti": "^2.6.1",

src/components/CopyButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export const CopyButton = ({
2020
text,
2121
iconOnly,
2222
size = "md",
23+
onCopy,
2324
...props
2425
}: {
2526
text: string
2627
iconOnly?: boolean
2728
size?: ButtonProps["size"]
29+
onCopy?: () => void
2830
} & ButtonProps) => {
2931
const [copied, setCopied] = useState(false)
3032
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
@@ -48,6 +50,7 @@ export const CopyButton = ({
4850
e.stopPropagation()
4951
setCopied(true)
5052
timeoutRef.current = setTimeout(() => setCopied(false), 2000)
53+
onCopy?.()
5154
}}
5255
{...(!iconOnly && {
5356
prefixIcon: <FileCopy size={size === "sm" ? "12px" : "16px"} />,

src/components/Drawer/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Button } from "../Button"
1111
import { ContentWrapper } from "./content-wrapper"
1212
import { Panel } from "../../components/Panel"
1313
import { XIcon, ArrowLeftIcon, ArrowRightIcon } from "@phosphor-icons/react"
14+
import { trackEvent } from "../../modules/ConsoleEventTracker"
15+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
1416

1517
type DrawerProps = {
1618
mode?: "modal" | "side"
@@ -143,10 +145,12 @@ export const Drawer = ({
143145
const canGoForward = useSelector(selectors.console.canGoForwardInSidebar)
144146

145147
const handleNavigateBack = () => {
148+
void trackEvent(ConsoleEvent.SIDEBAR_NAVIGATE)
146149
dispatch(actions.console.goBackInSidebar())
147150
}
148151

149152
const handleNavigateForward = () => {
153+
void trackEvent(ConsoleEvent.SIDEBAR_NAVIGATE)
150154
dispatch(actions.console.goForwardInSidebar())
151155
}
152156

src/components/ExplainQueryButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
executeAIFlow,
1414
createExplainFlowConfig,
1515
} from "../../utils/executeAIFlow"
16+
import { trackEvent } from "../../modules/ConsoleEventTracker"
17+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
1618

1719
const KeyBinding = styled(Box).attrs({ alignItems: "center", gap: "0" })`
1820
color: ${({ theme }) => theme.color.pinkPrimary};
@@ -55,6 +57,7 @@ export const ExplainQueryButton = ({
5557
} = useAIConversation()
5658

5759
const handleExplainQuery = () => {
60+
void trackEvent(ConsoleEvent.AI_EXPLAIN_QUERY)
5861
const currentModel = currentModelValue!
5962
const apiKey = apiKeyValue!
6063

src/components/FixQueryButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { useAIConversation } from "../../providers/AIConversationProvider"
1212
import { extractErrorByQueryKey } from "../../scenes/Editor/utils"
1313
import type { ExecutionRefs } from "../../scenes/Editor/index"
1414
import { executeAIFlow, createFixFlowConfig } from "../../utils/executeAIFlow"
15+
import { trackEvent } from "../../modules/ConsoleEventTracker"
16+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
1517

1618
const FixButton = styled(Button)`
1719
gap: 1rem;
@@ -40,6 +42,7 @@ export const FixQueryButton = () => {
4042
} = useAIConversation()
4143

4244
const handleFixQuery = () => {
45+
void trackEvent(ConsoleEvent.AI_FIX_QUERY)
4346
const conversationId = chatWindowState.activeConversationId!
4447
const conversation = getConversationMeta(conversationId)!
4548

src/components/LiteEditor/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { FileCopy } from "@styled-icons/remix-line"
99
import { CheckboxCircle } from "@styled-icons/remix-fill"
1010
import { copyToClipboard } from "../../utils/copyToClipboard"
1111
import { SquareSplitHorizontalIcon } from "@phosphor-icons/react"
12+
import { trackEvent } from "../../modules/ConsoleEventTracker"
13+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
1214

1315
const EditorWrapper = styled.div<{ $noBorder?: boolean }>`
1416
position: relative;
@@ -161,7 +163,12 @@ const LiteEditorToolbar = ({
161163
<ButtonsContainer>
162164
<OpenInEditorButton
163165
className="open-in-editor-btn"
164-
onClick={onOpenInEditor}
166+
onClick={() => {
167+
void trackEvent(ConsoleEvent.AI_OPEN_IN_EDITOR, {
168+
diffEditor,
169+
})
170+
onOpenInEditor()
171+
}}
165172
title="Open in editor"
166173
data-hook="ai-open-in-editor-button"
167174
>

src/components/SetupAIAssistant/ConfigurationModal.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { AnthropicIcon } from "./AnthropicIcon"
2626
import { BrainIcon } from "./BrainIcon"
2727
import { PlusIcon, Plugs as PlugsIcon } from "@phosphor-icons/react"
2828
import { theme } from "../../theme"
29+
import { trackEvent } from "../../modules/ConsoleEventTracker"
30+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
2931
import { CustomProviderModal } from "./CustomProviderModal"
3032

3133
const ModalContent = styled.div`
@@ -759,6 +761,11 @@ export const ConfigurationModal = ({
759761
const handleComplete = () => {
760762
if (!selectedProvider || enabledModels.length === 0) return
761763

764+
void trackEvent(ConsoleEvent.AI_PROVIDER_CONFIGURE, {
765+
name: selectedProvider,
766+
grantSchemaAccess,
767+
})
768+
762769
const selectedModel =
763770
enabledModels.find(
764771
(m) =>
@@ -825,6 +832,7 @@ export const ConfigurationModal = ({
825832
setEnabledModels(defaultModels)
826833
}
827834
setError(null)
835+
void trackEvent(ConsoleEvent.AI_CONFIGURATION_VALIDATE)
828836
return true
829837
} catch (err) {
830838
const errorMessage =
@@ -884,6 +892,13 @@ export const ConfigurationModal = ({
884892
},
885893
}
886894

895+
void trackEvent(ConsoleEvent.AI_PROVIDER_CONFIGURE, {
896+
name: "custom",
897+
grantSchemaAccess: definition.grantSchemaAccess ?? false,
898+
type: definition.type,
899+
contextWindow: definition.contextWindow,
900+
})
901+
887902
updateSettings(StoreKey.AI_ASSISTANT_SETTINGS, newSettings)
888903
toast.success("AI Assistant activated successfully")
889904
setCustomProviderModalOpen(false)

src/components/SetupAIAssistant/ModelDropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { AnthropicIcon } from "./AnthropicIcon"
1414
import { BrainIcon } from "./BrainIcon"
1515
import { PlugsIcon } from "@phosphor-icons/react"
1616
import { Tooltip } from "../Tooltip"
17+
import { trackEvent } from "../../modules/ConsoleEventTracker"
18+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
1719

1820
const ExpandUpDown = () => (
1921
<svg
@@ -173,6 +175,7 @@ export const ModelDropdown = () => {
173175
}, [enabledModelValues, aiAssistantSettings])
174176

175177
const handleModelSelect = (modelValue: string) => {
178+
void trackEvent(ConsoleEvent.AI_MODEL_CHANGE)
176179
updateSettings(StoreKey.AI_ASSISTANT_SETTINGS, {
177180
...aiAssistantSettings,
178181
selectedModel: modelValue,

src/components/SetupAIAssistant/SettingsModal.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import type {
3737
import { ForwardRef } from "../ForwardRef"
3838
import { Badge, BadgeType } from "../../components/Badge"
3939
import { CheckboxCircle } from "@styled-icons/remix-fill"
40+
import { trackEvent } from "../../modules/ConsoleEventTracker"
41+
import { ConsoleEvent } from "../../modules/ConsoleEventTracker/events"
4042
import { CustomProviderModal } from "./CustomProviderModal"
4143
import { ManageModelsModal } from "./ManageModelsModal"
4244

@@ -749,6 +751,7 @@ export const SettingsModal = ({ open, onOpenChange }: SettingsModalProps) => {
749751

750752
const handleModelToggle = useCallback(
751753
(provider: ProviderId, modelValue: string) => {
754+
void trackEvent(ConsoleEvent.AI_SETTINGS_MODEL_TOGGLE)
752755
setEnabledModels((prev) => {
753756
const current = prev[provider]
754757
const isEnabled = current.includes(modelValue)
@@ -765,6 +768,9 @@ export const SettingsModal = ({ open, onOpenChange }: SettingsModalProps) => {
765768

766769
const handleSchemaAccessChange = useCallback(
767770
(provider: ProviderId, checked: boolean) => {
771+
if (!checked) {
772+
void trackEvent(ConsoleEvent.AI_SETTINGS_SCHEMA_ACCESS_REMOVE)
773+
}
768774
setGrantSchemaAccess((prev) => ({ ...prev, [provider]: checked }))
769775
},
770776
[],
@@ -844,6 +850,9 @@ export const SettingsModal = ({ open, onOpenChange }: SettingsModalProps) => {
844850
const handleRemoveProvider = useCallback(
845851
(providerId: ProviderId) => {
846852
const isCustom = !BUILTIN_PROVIDERS[providerId]
853+
void trackEvent(ConsoleEvent.AI_SETTINGS_PROVIDER_REMOVE, {
854+
isCustom,
855+
})
847856

848857
if (isCustom) {
849858
setLocalCustomProviders((prev) => {
@@ -1216,6 +1225,9 @@ export const SettingsModal = ({ open, onOpenChange }: SettingsModalProps) => {
12161225
<EditButton
12171226
type="button"
12181227
onClick={() => {
1228+
void trackEvent(
1229+
ConsoleEvent.AI_SETTINGS_API_KEY_EDIT,
1230+
)
12191231
inputRef.current?.focus()
12201232
}}
12211233
title="Edit API key"

0 commit comments

Comments
 (0)