-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathmd-tracking.ts
More file actions
56 lines (52 loc) · 1.42 KB
/
md-tracking.ts
File metadata and controls
56 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { siteId } from "@/geistdocs";
import type { DetectionMethod } from "@/lib/ai-agent-detection";
const PLATFORM_URL = "https://geistdocs.com/md-tracking";
type TrackMdRequestParams = {
path: string;
userAgent: string | null;
referer: string | null;
acceptHeader: string | null;
/** How the markdown was requested: 'md-url' for direct .md URLs, 'header-negotiated' for Accept header */
requestType?: "md-url" | "header-negotiated" | "agent-rewrite";
/** Which detection method identified the AI agent */
detectionMethod?: DetectionMethod | null;
};
/**
* Track a markdown page request via the geistdocs platform.
* Fire-and-forget: errors are logged but don't affect the response.
*/
export async function trackMdRequest({
path,
userAgent,
referer,
acceptHeader,
requestType,
detectionMethod,
}: TrackMdRequestParams): Promise<void> {
try {
const response = await fetch(PLATFORM_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
path,
siteId: siteId ?? "geistdocs-unknown",
userAgent,
referer,
acceptHeader,
requestType,
detectionMethod,
}),
});
if (!response.ok) {
console.error(
"MD tracking failed:",
response.status,
await response.text()
);
}
} catch (error) {
console.error("MD tracking error:", error);
}
}