Skip to content

Commit fcb9cec

Browse files
committed
docs: track code copy + AI assistant event
1 parent ef162f8 commit fcb9cec

File tree

12 files changed

+74
-63
lines changed

12 files changed

+74
-63
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
"use client"
22

3-
import { Feedback as UiFeedback, FeedbackProps } from "docs-ui"
4-
import { usePathname } from "next/navigation"
3+
import {
4+
Feedback as UiFeedback,
5+
FeedbackProps,
6+
DocsTrackingEvents,
7+
} from "docs-ui"
58
import { useArea } from "../../providers/area"
69

710
export const Feedback = (props: Partial<FeedbackProps>) => {
8-
const pathname = usePathname()
911
const { area } = useArea()
1012

1113
return (
1214
<UiFeedback
1315
vertical={true}
1416
{...props}
15-
event="survey_api-ref"
17+
event={DocsTrackingEvents.SURVEY_API}
1618
extraData={{
1719
area,
1820
...props.extraData,
1921
}}
20-
pathName={`/api/${pathname}`}
2122
/>
2223
)
2324
}

www/apps/book/components/Feedback/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
"use client"
22

33
import {
4+
DocsTrackingEvents,
45
Feedback as UiFeedback,
56
FeedbackProps as UiFeedbackProps,
67
} from "docs-ui"
7-
import { usePathname } from "next/navigation"
8-
import { basePathUrl } from "../../utils/base-path-url"
9-
import { useMemo } from "react"
108

119
type FeedbackProps = Omit<UiFeedbackProps, "event" | "pathName">
1210

1311
const Feedback = (props: FeedbackProps) => {
14-
const pathname = usePathname()
15-
16-
const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname])
17-
1812
return (
1913
<UiFeedback
20-
event="survey"
21-
pathName={feedbackPathname}
14+
event={DocsTrackingEvents.SURVEY}
2215
question={props.question || "Was this chapter helpful?"}
2316
{...props}
2417
/>

www/apps/cloud/components/Feedback/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
"use client"
22

33
import {
4+
DocsTrackingEvents,
45
Feedback as UiFeedback,
56
FeedbackProps as UiFeedbackProps,
67
} from "docs-ui"
7-
import { usePathname } from "next/navigation"
8-
import { basePathUrl } from "../../utils/base-path-url"
9-
import { useMemo } from "react"
108

119
type FeedbackProps = Omit<UiFeedbackProps, "event" | "pathName">
1210

1311
const Feedback = (props: FeedbackProps) => {
14-
const pathname = usePathname()
15-
16-
const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname])
17-
1812
return (
1913
<UiFeedback
20-
event="survey"
21-
pathName={feedbackPathname}
14+
event={DocsTrackingEvents.SURVEY}
2215
question="Was this guide helpful?"
2316
{...props}
2417
/>

www/apps/resources/components/Feedback/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
"use client"
22

33
import {
4+
DocsTrackingEvents,
45
Feedback as UiFeedback,
56
FeedbackProps as UiFeedbackProps,
67
} from "docs-ui"
7-
import { usePathname } from "next/navigation"
8-
import { useMemo } from "react"
9-
import { basePathUrl } from "../../utils/base-path-url"
108

119
type FeedbackProps = Omit<UiFeedbackProps, "event" | "pathName">
1210

1311
export const Feedback = (props: FeedbackProps) => {
14-
const pathname = usePathname()
15-
16-
const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname])
17-
1812
return (
1913
<UiFeedback
20-
event="survey"
21-
pathName={feedbackPathname}
14+
event={DocsTrackingEvents.SURVEY}
2215
question="Was this page helpful?"
2316
{...props}
2417
/>

www/apps/ui/components/Feedback/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
"use client"
22

33
import {
4+
DocsTrackingEvents,
45
Feedback as UiFeedback,
56
FeedbackProps as UiFeedbackProps,
67
} from "docs-ui"
7-
import { usePathname } from "next/navigation"
8-
import { basePathUrl } from "../../utils/base-path-url"
9-
import { useMemo } from "react"
108

119
type FeedbackProps = Omit<UiFeedbackProps, "event" | "pathName">
1210

1311
const Feedback = (props: FeedbackProps) => {
14-
const pathname = usePathname()
15-
16-
const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname])
17-
1812
return (
1913
<UiFeedback
20-
event="survey"
21-
pathName={feedbackPathname}
14+
event={DocsTrackingEvents.SURVEY}
2215
question="Was this guide helpful?"
2316
{...props}
2417
/>

www/apps/user-guide/components/Feedback/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
"use client"
22

33
import {
4+
DocsTrackingEvents,
45
Feedback as UiFeedback,
56
FeedbackProps as UiFeedbackProps,
67
} from "docs-ui"
7-
import { usePathname } from "next/navigation"
8-
import { basePathUrl } from "../../utils/base-path-url"
9-
import { useMemo } from "react"
108

119
type FeedbackProps = Omit<UiFeedbackProps, "event" | "pathName">
1210

1311
const Feedback = (props: FeedbackProps) => {
14-
const pathname = usePathname()
15-
16-
const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname])
17-
1812
return (
1913
<UiFeedback
20-
event="survey"
21-
pathName={feedbackPathname}
14+
event={DocsTrackingEvents.SURVEY}
2215
question="Was this guide helpful?"
2316
{...props}
2417
/>

www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import React, { useEffect, useMemo, useRef } from "react"
22
import clsx from "clsx"
33
import { ArrowUpCircleSolid, LightBulb, LightBulbSolid } from "@medusajs/icons"
4-
import { useAiAssistant, useIsBrowser } from "../../../../providers"
4+
import {
5+
useAiAssistant,
6+
useAnalytics,
7+
useIsBrowser,
8+
} from "../../../../providers"
59
import { useChat, useDeepThinking } from "@kapaai/react-sdk"
610
import { useAiAssistantChatNavigation } from "../../../../hooks"
711
import { Tooltip } from "../../../Tooltip"
12+
import { DocsTrackingEvents } from "../../../../constants"
813

914
type AiAssistantChatWindowInputProps = {
1015
chatWindowRef: React.RefObject<HTMLDivElement | null>
@@ -16,6 +21,7 @@ export const AiAssistantChatWindowInput = ({
1621
const { chatOpened, inputRef, loading, setChatOpened, isCaptchaLoaded } =
1722
useAiAssistant()
1823
const { submitQuery, conversation } = useChat()
24+
const { track } = useAnalytics()
1925
const { active, toggle } = useDeepThinking()
2026
const { isBrowser } = useIsBrowser()
2127
const { searchQuery, searchQueryType } = useMemo(() => {
@@ -38,6 +44,13 @@ export const AiAssistantChatWindowInput = ({
3844
) => {
3945
e?.preventDefault()
4046
submitQuery(overrideQuestion || question)
47+
if (!conversation.length) {
48+
track({
49+
event: {
50+
event: DocsTrackingEvents.AI_ASSISTANT_START_CHAT,
51+
},
52+
})
53+
}
4154
setQuestion("")
4255
}
4356

www/packages/docs-ui/src/components/CodeBlock/Actions/Copy/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import React, { useEffect, useState } from "react"
4-
import { CopyButton } from "../../../.."
4+
import { CopyButton, DocsTrackingEvents, useAnalytics } from "../../../.."
55
import clsx from "clsx"
66
import { CheckMini, SquareTwoStack } from "@medusajs/icons"
77

@@ -15,13 +15,20 @@ export const CodeBlockCopyAction = ({
1515
inHeader,
1616
}: CodeBlockCopyActionProps) => {
1717
const [copied, setCopied] = useState(false)
18+
const { track } = useAnalytics()
1819

1920
useEffect(() => {
2021
if (copied) {
2122
setTimeout(() => {
2223
setCopied(false)
2324
}, 1000)
2425
}
26+
27+
track({
28+
event: {
29+
event: DocsTrackingEvents.CODE_BLOCK_COPY,
30+
},
31+
})
2532
}, [copied])
2633

2734
const iconClassName = [

www/packages/docs-ui/src/components/CodeBlock/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import React, { useEffect, useMemo, useRef, useState } from "react"
44
import clsx from "clsx"
55
import { Highlight, HighlightProps, themes, Token } from "prism-react-renderer"
66
import { ApiRunner } from "@/components"
7-
import { useColorMode } from "@/providers"
7+
import { useAnalytics, useColorMode } from "@/providers"
88
import { CodeBlockHeader, CodeBlockHeaderMeta } from "./Header"
99
import { CodeBlockLine } from "./Line"
1010
import { ApiAuthType, ApiDataOptions, ApiMethod } from "types"
1111
// @ts-expect-error can't install the types package because it doesn't support React v19
1212
import { CSSTransition } from "react-transition-group"
13-
import { useCollapsibleCodeLines } from "../.."
13+
import { DocsTrackingEvents, useCollapsibleCodeLines } from "../.."
1414
import { HighlightProps as CollapsibleHighlightProps } from "@/hooks"
1515
import { CodeBlockActions, CodeBlockActionsProps } from "./Actions"
1616
import { CodeBlockCollapsibleButton } from "./Collapsible/Button"
@@ -103,6 +103,7 @@ export const CodeBlock = ({
103103
}
104104

105105
const { colorMode } = useColorMode()
106+
const { track } = useAnalytics()
106107
const [showTesting, setShowTesting] = useState(false)
107108
const codeContainerRef = useRef<HTMLDivElement>(null)
108109
const codeRef = useRef<HTMLElement>(null)
@@ -296,6 +297,14 @@ export const CodeBlock = ({
296297
)
297298
}, [codeContainerRef.current, codeRef.current])
298299

300+
const trackCopy = () => {
301+
track({
302+
event: {
303+
event: DocsTrackingEvents.CODE_BLOCK_COPY,
304+
},
305+
})
306+
}
307+
299308
const actionsProps: Omit<CodeBlockActionsProps, "inHeader"> = useMemo(
300309
() => ({
301310
source,
@@ -435,6 +444,7 @@ export const CodeBlock = ({
435444
"pl-docs_1",
436445
preClassName
437446
)}
447+
onCopy={trackCopy}
438448
>
439449
<code
440450
className={clsx(

www/packages/docs-ui/src/components/Feedback/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { RadioGroup } from "@medusajs/ui"
2020

2121
export type FeedbackProps = {
2222
event: string
23-
pathName: string
2423
reportLink?: string
2524
question?: string
2625
positiveBtn?: string
@@ -55,7 +54,6 @@ const feedbackOptions = {
5554

5655
export const Feedback = ({
5756
event,
58-
pathName,
5957
reportLink: initReportLink,
6058
question = "Was this page helpful?",
6159
positiveBtn = "It was helpful",
@@ -106,15 +104,12 @@ export const Feedback = ({
106104
event: {
107105
event,
108106
options: {
109-
url: pathName,
110-
label: document.title,
111107
feedback:
112108
(feedback !== null && feedback) ||
113109
(feedback === null && positiveFeedback)
114110
? "yes"
115111
: "no",
116112
message: message?.length ? message : null,
117-
os: window.navigator.userAgent,
118113
feedbackOption,
119114
...extraData,
120115
},
@@ -124,7 +119,6 @@ export const Feedback = ({
124119
resetForm()
125120
}
126121
},
127-
tracker: ["segment", "posthog"],
128122
},
129123
})
130124
}

0 commit comments

Comments
 (0)