-
Notifications
You must be signed in to change notification settings - Fork 44
feat(agents): instrument /code/agents page with analytics events #2747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+182
−6
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
fd3864f
feat(agents): instrument /code/agents page with analytics events
andrewm4894 7f11b0d
fix(agents): gate AGENTS_VIEWED on success, not just !isLoading
andrewm4894 45d82bd
fix(agents): correct AGENTS_VIEWED payload + track failed setup attempts
andrewm4894 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/ui/src/features/agents/hooks/useTrackAgentsViewed.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events"; | ||
| import { track } from "@posthog/ui/shell/analytics"; | ||
| import { useEffect, useRef } from "react"; | ||
|
|
||
| export interface TrackAgentsViewedInput { | ||
| /** Gate the event until responder / integration / autonomy data has settled. */ | ||
| isLoading: boolean; | ||
| /** | ||
| * True when a backing fetch errored. An errored request also leaves | ||
| * `isLoading` false, so without this gate the event would fire with default | ||
| * values (e.g. `has_github_integration: false`) and `firedRef` would lock that | ||
| * bogus view in for the rest of the component's lifetime — mirrors the | ||
| * `!isSuccess` gate in `useTrackInboxViewed`. | ||
| */ | ||
| isError: boolean; | ||
| hasGithubIntegration: boolean; | ||
| responderTotalCount: number; | ||
| responderEnabledCount: number; | ||
| /** P0–P4, or null when the user's auto-start threshold is "Never". */ | ||
| autostartPriority: string | null; | ||
| setupTaskAvailable: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Fires `AGENTS_VIEWED` once per visit to the `/code/agents` configuration page, | ||
| * after the responder/integration/autonomy data settles, with the state the user | ||
| * sees on load. Mirrors `useTrackInboxViewed`; mounted from `ConfigureAgentsSection` | ||
| * where the data already lives, so it fires once and survives re-renders. | ||
| */ | ||
| export function useTrackAgentsViewed(input: TrackAgentsViewedInput): void { | ||
| const { | ||
| isLoading, | ||
| isError, | ||
| hasGithubIntegration, | ||
| responderTotalCount, | ||
| responderEnabledCount, | ||
| autostartPriority, | ||
| setupTaskAvailable, | ||
| } = input; | ||
|
|
||
| const firedRef = useRef(false); | ||
| useEffect(() => { | ||
| if (firedRef.current) return; | ||
| // Don't fire (and lock `firedRef`) until the data settled successfully: an | ||
| // errored fetch also clears `isLoading`, and firing then would capture a | ||
| // bogus default view that a later refetch can't correct. | ||
| if (isLoading || isError) return; | ||
| firedRef.current = true; | ||
| track(ANALYTICS_EVENTS.AGENTS_VIEWED, { | ||
| has_github_integration: hasGithubIntegration, | ||
| responder_total_count: responderTotalCount, | ||
| responder_enabled_count: responderEnabledCount, | ||
| autostart_priority: autostartPriority, | ||
| setup_task_available: setupTaskAvailable, | ||
| }); | ||
| }, [ | ||
| isLoading, | ||
| isError, | ||
| hasGithubIntegration, | ||
| responderTotalCount, | ||
| responderEnabledCount, | ||
| autostartPriority, | ||
| setupTaskAvailable, | ||
| ]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.