Skip to content

Commit cefdb24

Browse files
markrickertmorganick
authored andcommitted
Adds better types for analytics categories and actions
1 parent 587a5ff commit cefdb24

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

apps/reactotron-app/src/renderer/pages/customCommands/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function CustomCommandItem({
159159
<SendButton
160160
onClick={() => {
161161
sendCustomCommand(customCommand.command, state)
162-
sendCustomCommandAnalyticsEvent(customCommand.command, customCommand.title || "")
162+
sendCustomCommandAnalyticsEvent(customCommand.command)
163163
}}
164164
>
165165
Send Command

apps/reactotron-app/src/renderer/util/analyticsHelpers.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ import "react-confirm-alert/src/react-confirm-alert.css" // Import css
1111
// TODO: Change this to the correct key for production.
1212
const GA4_KEY = "G-WZE3E5XCQ7"
1313

14+
type IAnalyticsEventCategory =
15+
| { category: "android"; actions: ["settings", "reverse-tunnel", "reload-app", "shake-device"] }
16+
| { category: "navigation"; actions: ["keyboard_shortcut"] }
17+
| { category: "external_link"; actions: ["click"] }
18+
| { category: "timeline"; actions: ["search", "filter", "reverse", "clear"] }
19+
| { category: "error"; actions: ["OverlayDropImage"] }
20+
| { category: "overlay"; actions: ["OverlayDropImage", "OverlayRemoveImage", "OverlayShowDebug"] }
21+
| { category: "dispatch"; actions: ["dispatchAbort", "dispatchConfirm"] }
22+
| { category: "subscription"; actions: ["addAbort", "addConfirm", "add", "clear"] }
23+
| { category: "snapshot"; actions: ["copy", "restore", "remove", "copy", "add"] }
24+
| { category: "storybook"; actions: ["ToggleStorybook"] }
25+
| { category: "custom_command"; actions: ["sendCommand"] }
26+
1427
// I had trouble importing this type from the react-ga4 package, so I'm defining it here.
1528
type UaEventOptions = {
16-
action: string
17-
category: string
29+
category: IAnalyticsEventCategory["category"]
30+
action: IAnalyticsEventCategory["actions"][number]
1831
label?: string
1932
value?: number
2033
nonInteraction?: boolean
@@ -125,12 +138,12 @@ export const useAnalytics = () => {
125138

126139
// Send a custom command event
127140
const sendCustomCommandAnalyticsEvent = useCallback(
128-
(command: string, title: string) => {
141+
(command: string) => {
129142
sendAnalyticsEvent({
130143
category: "custom_command",
131-
action: command,
144+
action: "sendCommand",
132145
nonInteraction: false,
133-
label: title,
146+
label: command,
134147
})
135148
},
136149
[sendAnalyticsEvent]

0 commit comments

Comments
 (0)