diff --git a/src/components/codeBlock/index.tsx b/src/components/codeBlock/index.tsx index 54fd6e5c5f27c..68d319191b3e3 100644 --- a/src/components/codeBlock/index.tsx +++ b/src/components/codeBlock/index.tsx @@ -3,6 +3,8 @@ import {RefObject, useEffect, useRef, useState} from 'react'; import {Clipboard} from 'react-feather'; +import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent'; + import styles from './code-blocks.module.scss'; import {makeHighlightBlocks} from '../codeHighlights'; @@ -47,6 +49,7 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) { // Show the copy button after js has loaded // otherwise the copy button will not work const [showCopyButton, setShowCopyButton] = useState(false); + const {emit} = usePlausibleEvent(); useEffect(() => { setShowCopyButton(true); @@ -83,6 +86,7 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) { try { await navigator.clipboard.writeText(code); setShowCopied(true); + emit('copy sentry code', {props: {page: window.location.pathname}}); setTimeout(() => setShowCopied(false), 1200); } catch (error) { // eslint-disable-next-line no-console diff --git a/src/hooks/usePlausibleEvent.tsx b/src/hooks/usePlausibleEvent.tsx index aeeac51454907..a9491efec6207 100644 --- a/src/hooks/usePlausibleEvent.tsx +++ b/src/hooks/usePlausibleEvent.tsx @@ -35,6 +35,9 @@ type PlausibleEventProps = { page: string; source: string; }; + ['copy sentry code']: { + page: string; + }; }; /**