返回 CodeWhale
funnel.ts
根目录 / web / lib / telemetry / funnel.ts
1 import { DOC_TOPICS } from "../docs-map";
2 import { locales } from "../i18n/config";
3 import type { FunnelCounter } from "./product-usage";
4
5 const languages = new Set(locales.map((locale) => locale.toLowerCase()));
6 const documentationRoots = new Set(DOC_TOPICS.filter((topic) => topic.hasPage && topic.sitePath).map((topic) => `/${topic.sitePath}`));
7
8 export function funnelPath(pathname: string): { view: FunnelCounter | null; documentation: boolean } {
9 const parts = pathname.split("/").filter(Boolean);
10 if (languages.has(parts[0]?.toLowerCase())) parts.shift();
11 const path = `/${parts.join("/")}`;
12 const views: Record<string, FunnelCounter> = {
13 "/": "home_view", "/install": "install_view", "/docs/guide": "quickstart_view", "/contribute": "contribute_view",
14 };
15 return {
16 view: views[path] ?? null,
17 documentation: path === "/docs" || path.startsWith("/docs/") || documentationRoots.has(path),
18 };
19 }
20
21 export function funnelExit(href: string): FunnelCounter | null {
22 let url: URL;
23 try { url = new URL(href, "https://codewhale.net"); } catch { return null; }
24 if (url.hostname !== "github.com" || url.protocol !== "https:") return null;
25 const path = url.pathname.toLowerCase().replace(/\/$/, "");
26 if (path === "/codewhale-hq/codewhale/issues/new" || path === "/codewhale-hq/codewhale/issues/new/choose") return "issue_exit";
27 if (path === "/codewhale-hq/codewhale/blob/main/contributing.md") return "guide_exit";
28 if (path === "/codewhale-hq/codewhale/issues" && /label:(?:"help wanted"|help wanted)(?:\s|$)/.test(url.searchParams.get("q") ?? "")) return "help_wanted_exit";
29 return null;
30 }
31
31 lines TYPESCRIPT