docs: track code copy + AI assistant event (#14193)
* docs: track code copy + AI assistant event * add pathname to callback
This commit is contained in:
@@ -4,13 +4,13 @@ import React, { useEffect, useMemo, useRef, useState } from "react"
|
||||
import clsx from "clsx"
|
||||
import { Highlight, HighlightProps, themes, Token } from "prism-react-renderer"
|
||||
import { ApiRunner } from "@/components"
|
||||
import { useColorMode } from "@/providers"
|
||||
import { useAnalytics, useColorMode } from "@/providers"
|
||||
import { CodeBlockHeader, CodeBlockHeaderMeta } from "./Header"
|
||||
import { CodeBlockLine } from "./Line"
|
||||
import { ApiAuthType, ApiDataOptions, ApiMethod } from "types"
|
||||
// @ts-expect-error can't install the types package because it doesn't support React v19
|
||||
import { CSSTransition } from "react-transition-group"
|
||||
import { useCollapsibleCodeLines } from "../.."
|
||||
import { DocsTrackingEvents, useCollapsibleCodeLines } from "../.."
|
||||
import { HighlightProps as CollapsibleHighlightProps } from "@/hooks"
|
||||
import { CodeBlockActions, CodeBlockActionsProps } from "./Actions"
|
||||
import { CodeBlockCollapsibleButton } from "./Collapsible/Button"
|
||||
@@ -103,6 +103,7 @@ export const CodeBlock = ({
|
||||
}
|
||||
|
||||
const { colorMode } = useColorMode()
|
||||
const { track } = useAnalytics()
|
||||
const [showTesting, setShowTesting] = useState(false)
|
||||
const codeContainerRef = useRef<HTMLDivElement>(null)
|
||||
const codeRef = useRef<HTMLElement>(null)
|
||||
@@ -296,6 +297,14 @@ export const CodeBlock = ({
|
||||
)
|
||||
}, [codeContainerRef.current, codeRef.current])
|
||||
|
||||
const trackCopy = () => {
|
||||
track({
|
||||
event: {
|
||||
event: DocsTrackingEvents.CODE_BLOCK_COPY,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const actionsProps: Omit<CodeBlockActionsProps, "inHeader"> = useMemo(
|
||||
() => ({
|
||||
source,
|
||||
@@ -435,6 +444,7 @@ export const CodeBlock = ({
|
||||
"pl-docs_1",
|
||||
preClassName
|
||||
)}
|
||||
onCopy={trackCopy}
|
||||
>
|
||||
<code
|
||||
className={clsx(
|
||||
|
||||
Reference in New Issue
Block a user