Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/components/Community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export function Community() {
asChild
className="bg-transparent border-[var(--foreground)] text-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] px-12 py-8 h-auto font-sans text-sm uppercase tracking-widest font-bold"
>
<a href="docs/ai" target="_blank" rel="noopener noreferrer">
<a
href="docs/ai"
target="_blank"
rel="noopener noreferrer"
data-umami-event="navigation_click"
data-umami-event-region="community_section"
data-umami-event-label="Access Articles"
>
Access Articles / 访问文章{" "}
<ExternalLink className="ml-4 h-5 w-5" />
</a>
Expand Down Expand Up @@ -73,6 +80,9 @@ export function Community() {
href="https://github.com/involutionhell"
target="_blank"
rel="noopener noreferrer"
data-umami-event="resource_click"
data-umami-event-type="github_repo"
data-umami-event-location="community_card"
>
Source Code <ExternalLink className="ml-2 h-4 w-4" />
</a>
Expand All @@ -98,6 +108,9 @@ export function Community() {
href="https://discord.com/invite/6CGP73ZWbD"
target="_blank"
rel="noopener noreferrer"
data-umami-event="resource_click"
data-umami-event-type="discord_invite"
data-umami-event-location="community_card"
>
Join Dispatch <ExternalLink className="ml-2 h-4 w-4" />
</a>
Expand All @@ -123,6 +136,9 @@ export function Community() {
href="https://www.zotero.org/groups/6053219/unsw_ai/library"
target="_blank"
rel="noopener noreferrer"
data-umami-event="resource_click"
data-umami-event-type="zotero"
data-umami-event-location="community_card"
>
View Library <ExternalLink className="ml-2 h-4 w-4" />
</a>
Expand Down
10 changes: 10 additions & 0 deletions app/components/Contribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export function Contribute() {
if (filename !== articleFile) {
setArticleFile(filename);
}

if (window.umami) {
window.umami.track("contribute_github_redirect", {
dir: finalDirPath,
filename: filename,
});
}

window.open(
buildGithubNewUrl(finalDirPath, filename, title),
"_blank",
Expand Down Expand Up @@ -162,6 +170,8 @@ export function Contribute() {
text-2xl font-serif font-black uppercase italic tracking-tighter
bg-[var(--foreground)] text-[var(--background)] border border-[var(--foreground)]
hover:bg-[var(--background)] hover:text-[var(--foreground)] transition-all duration-300"
data-umami-event="contribute_trigger"
data-umami-event-location="hero"
onClick={(event) => {
event.preventDefault();
router.push("/editor");
Expand Down
125 changes: 125 additions & 0 deletions app/components/CustomSearchDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"use client";

import { useEffect, useMemo, useState } from "react";
import { useDocsSearch } from "fumadocs-core/search/client";
import { useI18n } from "fumadocs-ui/provider";
import {
SearchDialog,
SearchDialogContent,
SearchDialogHeader,
SearchDialogInput,
SearchDialogList,
SearchDialogFooter,
SearchDialogOverlay,
SearchDialogIcon,
SearchDialogClose,
TagsList,
TagsListItem,
type SharedProps,
} from "fumadocs-ui/components/dialog/search";

interface TagItem {
name: string;
value: string;
}

interface DefaultSearchDialogProps extends SharedProps {
links?: [string, string][];
type?: "fetch" | "static";
defaultTag?: string;
tags?: TagItem[];
api?: string;
delayMs?: number;
footer?: React.ReactNode;
allowClear?: boolean;
}

export function CustomSearchDialog({
defaultTag,
tags = [],
api,
delayMs,
type = "fetch",
allowClear = false,
links = [],
footer,
...props
}: DefaultSearchDialogProps) {
const { locale } = useI18n();
const [tag, setTag] = useState(defaultTag);
const { search, setSearch, query } = useDocsSearch(
type === "fetch"
? {
type: "fetch",
api,
locale,
tag,
delayMs,
}
: {
type: "static",
from: api,
locale,
tag,
delayMs,
},
);

// Tracking logic
useEffect(() => {
if (!search) return;

const timer = setTimeout(() => {
if (window.umami) {
window.umami.track("search_query", { query: search });
}
}, 1000); // 1s debounce

return () => clearTimeout(timer);
}, [search]);

const defaultItems = useMemo(() => {
if (links.length === 0) return null;
return links.map(([name, link]) => ({
type: "page" as const,
id: name,
content: name,
url: link,
}));
}, [links]);

return (
<SearchDialog
search={search}
onSearchChange={setSearch}
isLoading={query.isLoading}
{...props}
>
<SearchDialogOverlay />
<SearchDialogContent>
<SearchDialogHeader>
<SearchDialogIcon />
<SearchDialogInput />
<SearchDialogClose />
</SearchDialogHeader>
<SearchDialogList
items={
query.data !== "empty" && query.data ? query.data : defaultItems
}
/>
</SearchDialogContent>
<SearchDialogFooter>
{tags.length > 0 && (
<TagsList tag={tag} onTagChange={setTag} allowClear={allowClear}>
{tags.map((tag) => (
<TagsListItem key={tag.value} value={tag.value}>
{tag.name}
</TagsListItem>
))}
</TagsList>
)}
{footer}
</SearchDialogFooter>
</SearchDialog>
);
}
10 changes: 9 additions & 1 deletion app/components/DocsAssistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ function DocsAssistantInner({ pageContext }: DocsAssistantProps) {
[geminiApiKey, openaiApiKey, pageContext, provider],
);

const chat = useChat({ transport });
const chat = useChat({
transport,
onFinish: () => {
// 当对话结束时(流式传输完成),记录一次查询行为
if (window.umami) {
window.umami.track("ai_assistant_query");
}
},
});

const {
error: chatError,
Expand Down
2 changes: 2 additions & 0 deletions app/components/EditOnGithub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export function EditOnGithub({ href }: { href: string }) {
<Link
href={href}
className="inline-flex items-center gap-2 rounded-md px-4 h-11 text-base font-medium hover:bg-muted/80 hover:text-foreground no-underline"
data-umami-event="docs_edit_click"
data-umami-event-page={href}
>
<svg
aria-hidden="true"
Expand Down
2 changes: 2 additions & 0 deletions app/components/Features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function Features() {
<div
key={index}
className="group relative border-r border-b border-[var(--foreground)] p-12 hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors"
data-umami-event="feature_card_hover"
data-umami-event-title={feature.title}
>
<div className="flex flex-col h-full">
<div className="flex items-center justify-between mb-8">
Expand Down
22 changes: 22 additions & 0 deletions app/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function Footer() {
rel="noopener noreferrer"
aria-label="访问 GitHub"
title="访问 GitHub"
data-umami-event="social_click"
data-umami-event-platform="github"
data-umami-event-location="footer"
className="w-12 h-12 flex items-center justify-center border border-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] transition-all text-[var(--foreground)]"
>
<Github className="h-5 w-5" />
Expand All @@ -38,6 +41,9 @@ export function Footer() {
rel="noopener noreferrer"
aria-label="加入 Discord 社区"
title="加入 Discord 社区"
data-umami-event="social_click"
data-umami-event-platform="discord"
data-umami-event-location="footer"
className="w-12 h-12 flex items-center justify-center border border-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] transition-all text-[var(--foreground)]"
>
<MessageCircle className="h-5 w-5" />
Expand All @@ -57,6 +63,9 @@ export function Footer() {
<Link
href="/docs/ai"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="footer"
data-umami-event-label="AI & Mathematics"
>
AI & Mathematics
</Link>
Expand All @@ -65,6 +74,9 @@ export function Footer() {
<Link
href="/docs/computer-science"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="footer"
data-umami-event-label="Computer Science"
>
Computer Science
</Link>
Expand All @@ -73,6 +85,9 @@ export function Footer() {
<Link
href="/docs/CommunityShare"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="footer"
data-umami-event-label="Community Sharing"
>
Community Sharing
</Link>
Expand All @@ -81,6 +96,9 @@ export function Footer() {
<Link
href="/docs/jobs"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="footer"
data-umami-event-label="Career Prep"
>
Career Prep
</Link>
Expand All @@ -99,6 +117,10 @@ export function Footer() {
target="_blank"
rel="noopener noreferrer"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="resource_click"
data-umami-event-type="zotero"
data-umami-event-location="footer"
data-umami-event-url="https://www.zotero.org/groups/6053219/unsw_ai/library"
>
Zotero Library
</a>
Expand Down
15 changes: 15 additions & 0 deletions app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,27 @@ export async function Header() {
<a
href="#features"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="header"
data-umami-event-label="features"
>
特点
</a>
<a
href="#community"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="header"
data-umami-event-label="community"
>
社区
</a>
<a
href="#contact"
className="hover:text-[#CC0000] transition-colors"
data-umami-event="navigation_click"
data-umami-event-region="header"
data-umami-event-label="contact"
>
联系我们
</a>
Expand All @@ -68,6 +77,9 @@ export async function Header() {
target="_blank"
rel="noopener noreferrer"
aria-label="GitHub"
data-umami-event="social_click"
data-umami-event-platform="github"
data-umami-event-location="header"
>
<GithubIcon className="h-4 w-4" />
</a>
Expand All @@ -83,6 +95,9 @@ export async function Header() {
target="_blank"
rel="noopener noreferrer"
aria-label="Discord"
data-umami-event="social_click"
data-umami-event-platform="discord"
data-umami-event-location="header"
>
<MessageCircle className="h-4 w-4" />
</a>
Expand Down
10 changes: 9 additions & 1 deletion app/components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ export function Hero() {
Connect with thousands of developers who are reclaiming their
passion for technology.
</p>
<Link href="/docs/ai" className="block w-full">
<Link
href="/docs/ai"
className="block w-full"
data-umami-event="feature_cta_click"
data-umami-event-action="access_articles"
data-umami-event-location="hero_sidebar"
>
<button className="w-full py-3 border border-[var(--background)] font-sans text-xs uppercase tracking-widest hover:bg-[var(--background)] hover:text-[var(--foreground)] transition-all cursor-pointer">
Access Articles / 访问文章
</button>
Expand All @@ -107,6 +113,8 @@ export function Hero() {
<Link
href={c.href}
className="p-8 hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors h-full flex flex-col hard-shadow-hover"
data-umami-event="home_category_click"
data-umami-event-category={c.title}
>
<div className="font-mono text-[10px] text-neutral-400 mb-4">
00{idx + 1}
Expand Down
9 changes: 8 additions & 1 deletion app/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export function SignInButton({
});
}}
>
<Button type="submit" size="sm" variant="outline">
<Button
type="submit"
size="sm"
variant="outline"
data-umami-event="auth_click"
data-umami-event-action="signin"
data-umami-event-location="header"
>
SignIn
</Button>
</form>
Expand Down
3 changes: 3 additions & 0 deletions app/components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function ThemeToggle() {
onClick={() => {
const next = theme === "light" ? "dark" : "light";
setTheme(next);
if (window.umami) {
window.umami.track("theme_toggle", { theme: next });
}
}}
className="h-10 w-10 rounded-none transition-colors"
>
Expand Down
Loading
Loading