Conversation
Adds a Claude Code skill for adding frontend analytics events to the Sentry codebase. Covers: - Button click analytics (analyticsEventKey/analyticsEventName props) - Manual trackAnalytics() for non-button events - Event type definitions and naming conventions
| **Use button props for click tracking whenever possible.** This is the simplest approach and provides automatic tracking. | ||
|
|
||
| ```tsx | ||
| <Button |
There was a problem hiding this comment.
do this button prop analytic event tracking pick up default params like user id and org and whatnot?
| @@ -0,0 +1,118 @@ | |||
| --- | |||
| name: sentry-analytics | |||
| ### 1. Define event types | ||
|
|
||
| Add to appropriate file in `static/app/utils/analytics/` (e.g., `featureAnalyticsEvents.tsx`): | ||
|
|
||
| ```typescript | ||
| export type FeatureEventParameters = { | ||
| 'feature_name.action_performed': { | ||
| source: string; | ||
| }; | ||
| 'feature_name.modal_opened': Record<string, unknown>; // No params | ||
| }; | ||
|
|
||
| export const featureEventMap: Record<keyof FeatureEventParameters, string | null> = { | ||
| 'feature_name.action_performed': 'Feature Name: Action Performed', // Amplitude name | ||
| 'feature_name.modal_opened': null, // null = don't send to Amplitude | ||
| }; | ||
| ``` | ||
|
|
||
| ### 2. Register in index | ||
|
|
||
| Add to `static/app/utils/analytics/index.tsx`: | ||
|
|
||
| ```typescript | ||
| import {featureEventMap, type FeatureEventParameters} from './featureAnalyticsEvents'; | ||
|
|
||
| export type EventParameters = | ||
| // ... existing types | ||
| FeatureEventParameters; | ||
|
|
||
| export const allEventMap = { | ||
| // ... existing maps | ||
| ...featureEventMap, | ||
| }; | ||
| ``` | ||
|
|
||
| ### 3. Track the event | ||
|
|
||
| ```typescript | ||
| import {trackAnalytics} from 'sentry/utils/analytics'; | ||
|
|
||
| trackAnalytics('feature_name.action_performed', { | ||
| organization, | ||
| source: 'modal', | ||
| }); | ||
| ``` |
There was a problem hiding this comment.
i assume this is only needed if we don't use the button props stuff?
There was a problem hiding this comment.
Exactly, but tbh, I'd prefer to just have explicit trackAnalytics calls, it will work cross all different components and be more explicit. These props are only supported on the button component too, which is super wonky from an API consistency pov
There was a problem hiding this comment.
gotcha, so maybe it sounds like for simple buttons it makes sense to use them, but if you need any additional props you should use trackAnalyticsEvents in the onclick handler?
There was a problem hiding this comment.
I'd go even further and just say use the trackAnalyticsEvent function all the time. Nobody ever knows these props exist, and what seems like a convenience thing turns into confusion.
I'd bet that even for simple stuff, people end up calling trackAnalyticsEvent and it's the same reason why people write <Tooltip><Button/></Tooltip> even thought they could use tooltipProps from the button.
| ```typescript | ||
| useEffect(() => { | ||
| trackAnalytics('feature.viewed', {organization}); | ||
| }, [organization]); |
There was a problem hiding this comment.
we don't want people to create effects for this since really what you want is a debounce for things like loading. we have a useRouteAnalyticsEventNames and useRouteAnalyticsParams
There was a problem hiding this comment.
i guess that mostly only makes sense for page level analytics, but most are when counting views
|
@JoshFerge I would add one thing here which is to guide AI away from useEffect and observing state, and to instead add trackAnalyticsEvent to the existing callbacks. For example const [toggle, setToggle] = useState()
<input type="radio" onChange={() => setToggle(!toggle)}shouldn't become (also likely unwanted as it will fire on initial render) const [toggle, setToggle] = useState();
useEffect(() => trackAnalytics(...), [toggle])
<input type="radio" onChange={() => setToggle(!toggle)}/>but should instead just be const [toggle, setToggle] = useState()
<input type="radio" onChange={() => {
trackAnalytics(!toggle)
setToggle(!toggle)
}}/> |
Summary
Adds a Claude Code skill for adding frontend analytics events to the Sentry codebase.
What the skill covers
analyticsEventKey,analyticsEventName, andanalyticsParamsprops (preferred approach)Usage
The skill will be automatically triggered when asking Claude to add analytics events. It provides guidance on:
trackAnalytics()insteadseerAnalyticsEvents.tsxor similarDEBUG_ANALYTICS=1Test plan
/sentry-analytics