Skip to content

Commit 1cf669d

Browse files
authored
[Docs Site] Add tracking events and hide footer elements on DocsAI (#22998)
* [Docs Site] Add tracking events and hide footer elements on DocsAI * use a custom component rather than dom * fix desc
1 parent 4e43233 commit 1cf669d

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

src/components/DocsAI.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import remarkGfm from "remark-gfm";
55
import { fetchEventSource } from "@microsoft/fetch-event-source";
66
import { Ring } from "ldrs/react";
77
import { MdOutlineThumbUp, MdOutlineThumbDown } from "react-icons/md";
8+
import { track } from "~/util/zaraz";
89
import "ldrs/react/Ring.css";
910

1011
type Messages = {
@@ -31,6 +32,29 @@ async function sendCSATFeedback(queryId: string, positive: boolean) {
3132
}
3233
}
3334

35+
function TrackedLink({
36+
href,
37+
children,
38+
}: {
39+
href?: string;
40+
children?: React.ReactNode;
41+
}) {
42+
return (
43+
<a
44+
href={href}
45+
target="_blank"
46+
onClick={() =>
47+
track("click chat link", {
48+
value: children?.toString() ?? "",
49+
href,
50+
})
51+
}
52+
>
53+
{children}
54+
</a>
55+
);
56+
}
57+
3458
function Messages({
3559
messages,
3660
loading,
@@ -47,6 +71,9 @@ function Messages({
4771
};
4872

4973
const handleFeedback = async (queryId: string, positive: boolean) => {
74+
track("submit chat feedback", {
75+
value: positive.toString(),
76+
});
5077
await sendCSATFeedback(queryId, positive);
5178
setFeedbackGiven((prev) => new Set(prev).add(queryId));
5279
};
@@ -60,7 +87,12 @@ function Messages({
6087
<div
6188
className={`${classes.base} ${message.role === "user" ? classes.user : classes.assistant}`}
6289
>
63-
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>
90+
<Markdown
91+
remarkPlugins={[remarkGfm, remarkBreaks]}
92+
components={{
93+
a: TrackedLink,
94+
}}
95+
>
6496
{message.content}
6597
</Markdown>
6698
{message.sources && (
@@ -71,10 +103,10 @@ function Messages({
71103
</p>
72104
<ul>
73105
{message.sources.map((source) => (
74-
<li>
75-
<a href={source.file_path} target="_blank">
106+
<li key={source.file_path}>
107+
<TrackedLink href={source.file_path}>
76108
{source.title}
77-
</a>
109+
</TrackedLink>
78110
</li>
79111
))}
80112
</ul>
@@ -124,6 +156,10 @@ export default function SupportAI() {
124156
const [messages, setMessages] = useState<Messages>([]);
125157

126158
async function handleSubmit() {
159+
track("submit chat", {
160+
value: question,
161+
});
162+
127163
setLoading(true);
128164
setMessages((messages) => [
129165
...messages,

src/components/overrides/Footer.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const links = Object.entries({
7070
7171
const homepage = Astro.locals.starlightRoute.entry.id === "";
7272
const splash = Astro.locals.starlightRoute.entry.data.template === "splash";
73+
const showFeedback = Astro.locals.starlightRoute.entry.data.feedback;
7374
7475
let isProduction = false;
7576
@@ -82,7 +83,7 @@ if (
8283
---
8384

8485
{
85-
!homepage && (
86+
!homepage && showFeedback && (
8687
<div class="feedback-prompt">
8788
<FeedbackPrompt client:idle />
8889
</div>

src/components/overrides/Page.astro

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ if (props.hasSidebar) {
3939
};
4040
}
4141
42-
props.pagination.prev = prev;
43-
props.pagination.next = next;
42+
if (data.prev !== false) {
43+
props.pagination.prev = prev;
44+
}
45+
46+
if (data.next !== false) {
47+
props.pagination.next = next;
48+
}
4449
}
4550
}
4651

src/components/overrides/TableOfContents.astro

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Icon } from "@astrojs/starlight/components";
55
import FeedbackPrompt from "../FeedbackPrompt.tsx";
66
77
const tags = Astro.locals.starlightRoute.entry.data.tags;
8+
const showFeedback = Astro.locals.starlightRoute.entry.data.feedback;
89
---
910

1011
<Default />
@@ -29,8 +30,14 @@ const tags = Astro.locals.starlightRoute.entry.data.tags;
2930
</>
3031
)
3132
}
32-
<br />
33-
<FeedbackPrompt client:idle />
33+
{
34+
showFeedback && (
35+
<>
36+
<br />
37+
<FeedbackPrompt client:idle />
38+
</>
39+
)
40+
}
3441
{
3542
!Astro.url.pathname.startsWith("/support/") && (
3643
<>

src/content/docs/support/ai.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ sidebar:
55
order: 8
66
label: Docs AI
77
badge: Beta
8+
next: false
9+
prev: false
10+
feedback: false
811
---
912

1013
import DocsAI from "~/components/DocsAI.tsx";

src/schemas/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ export const baseSchema = ({ image }: SchemaContext) =>
131131
})
132132
.optional(),
133133
icon: SidebarIconSchema(),
134+
feedback: z
135+
.boolean()
136+
.default(true)
137+
.describe(
138+
"Whether to show the FeedbackPrompt on the page, defaults to true",
139+
),
134140
});

src/styles/tailwind.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
}
145145

146146
@layer base {
147+
pre {
148+
white-space: pre-wrap;
149+
}
150+
147151
:root {
148152
--blue-accent-200: rgb(15, 0, 107);
149153
--blue-accent-600: rgb(46, 105, 255);

0 commit comments

Comments
 (0)