Skip to content

Commit 85615d5

Browse files
sfanahataShannon Anahata
andauthored
feat: add Sentry metric for Copy Prompt button clicks (#18264)
## DESCRIBE YOUR PR - **Preview has been validated** - **Sentry data has been validated (see vercel preview in Sentry!)**** Track "Copy Prompt" button clicks in the Agent Skills Callout as a Sentry application metric (`docs.copy_ai_prompt` counter). **Metric attributes:** - `page_path` -- first 3 URL segments (privacy-safe, matches existing metrics) - `skill` -- skill name (e.g. `sentry-nextjs-sdk`) or `generic` if no skill specified - `success` -- whether the clipboard copy succeeded **Changes (2 files):** - `src/metrics.ts` -- Add `copyAIPrompt` method to `DocMetrics`, following the same pattern as existing metrics (`copyPage`, `snippetCopy`, etc.) - `src/components/agentSkillsCallout/index.tsx` -- Import `DocMetrics` and call `copyAIPrompt` on success/failure in the click handler. Also fixes `useCallback` dependency array to include `skill`. ## IS YOUR CHANGE URGENT? - [x] None: Not urgent, can wait up to 1 week+ ## PRE-MERGE CHECKLIST - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) Co-authored-by: Shannon Anahata <shannonanahata@gmail.com>
1 parent 2ea6c18 commit 85615d5

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/components/agentSkillsCallout/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Sentry from '@sentry/nextjs';
55
import Link from 'next/link';
66
import {useCallback, useState} from 'react';
77
import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent';
8+
import {DocMetrics} from 'sentry-docs/metrics';
89

910
import {CodeBlock} from '../codeBlock';
1011
import {CodeTabs} from '../codeTabs';
@@ -66,13 +67,15 @@ export function AgentSkillsCallout({skill, platformName}: Props) {
6667
setCopied(false);
6768
await navigator.clipboard.writeText(prompt);
6869
setCopied(true);
70+
DocMetrics.copyAIPrompt(window.location.pathname, skill, true);
6971
setTimeout(() => setCopied(false), 1500);
7072
} catch (error) {
7173
Sentry.captureException(error);
74+
DocMetrics.copyAIPrompt(window.location.pathname, skill, false);
7275
setCopied(false);
7376
}
7477
},
75-
[prompt, emit]
78+
[prompt, emit, skill]
7679
);
7780

7881
const description = platformName

src/metrics.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ export const DocMetrics = {
135135
},
136136
});
137137
},
138+
139+
/**
140+
* Track "Copy Prompt" button clicks in the Agent Skills Callout
141+
* @param pathname - Page where the prompt was copied
142+
* @param skill - Skill name if present (e.g., "sentry-nextjs-sdk")
143+
* @param success - Whether the clipboard copy succeeded
144+
*/
145+
copyAIPrompt: (pathname: string, skill: string | undefined, success: boolean) => {
146+
Sentry.metrics.count('docs.copy_ai_prompt', 1, {
147+
attributes: {
148+
page_path: pathname.split('/').slice(0, 3).join('/'), // First 3 segments
149+
skill: skill || 'generic',
150+
success,
151+
},
152+
});
153+
},
138154
};
139155

140156
/**

0 commit comments

Comments
 (0)