2027-track 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/dist/chunk-Z3U3YF4H.mjs +46 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +70 -0
- package/dist/index.mjs +6 -0
- package/dist/next.d.mts +6 -0
- package/dist/next.d.ts +6 -0
- package/dist/next.js +91 -0
- package/dist/next.mjs +24 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# 2027-track
|
|
2
|
+
|
|
3
|
+
Track AI coding agents (Claude Code, Codex, OpenCode) visiting your documentation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install 2027-track
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage with Next.js
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// middleware.ts
|
|
15
|
+
import { withAIAnalytics } from "2027-track/next";
|
|
16
|
+
|
|
17
|
+
export default withAIAnalytics();
|
|
18
|
+
|
|
19
|
+
// Or wrap your existing middleware:
|
|
20
|
+
export default withAIAnalytics(yourExistingMiddleware);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage (generic)
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { trackVisit } from "2027-track";
|
|
27
|
+
|
|
28
|
+
await trackVisit({
|
|
29
|
+
host: "docs.example.com",
|
|
30
|
+
path: "/api/getting-started",
|
|
31
|
+
userAgent: request.headers.get("user-agent"),
|
|
32
|
+
accept: request.headers.get("accept"),
|
|
33
|
+
country: "US", // optional
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
### Kill switch
|
|
40
|
+
|
|
41
|
+
Set `AI_ANALYTICS_ENDPOINT=""` to disable tracking entirely.
|
|
42
|
+
|
|
43
|
+
### Custom endpoint
|
|
44
|
+
|
|
45
|
+
Set `AI_ANALYTICS_ENDPOINT` to your own endpoint URL.
|
|
46
|
+
|
|
47
|
+
## Privacy
|
|
48
|
+
|
|
49
|
+
- Events are sent **server-side** from Vercel Edge (or your server)
|
|
50
|
+
- Visitor IP addresses **never reach** the analytics endpoint
|
|
51
|
+
- Only headers (user-agent, accept) and page info (host, path) are sent
|
|
52
|
+
|
|
53
|
+
## Detection
|
|
54
|
+
|
|
55
|
+
| Agent | Signal |
|
|
56
|
+
|-------|--------|
|
|
57
|
+
| Claude Code | `axios` user-agent + `text/markdown` accept |
|
|
58
|
+
| OpenCode | `text/markdown` accept with `q=` weights |
|
|
59
|
+
| Codex | `ChatGPT-User` user-agent |
|
|
60
|
+
|
|
61
|
+
Dashboard: https://ai-docs-analytics.vercel.app
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_ENDPOINT = "https://ai-docs-analytics-api.theisease.workers.dev/track";
|
|
3
|
+
var TIMEOUT_MS = 2500;
|
|
4
|
+
function getEndpoint() {
|
|
5
|
+
const env = typeof process !== "undefined" ? process.env.AI_ANALYTICS_ENDPOINT : void 0;
|
|
6
|
+
if (env === "") return null;
|
|
7
|
+
return env || DEFAULT_ENDPOINT;
|
|
8
|
+
}
|
|
9
|
+
function shouldTrack(accept) {
|
|
10
|
+
const a = accept.toLowerCase();
|
|
11
|
+
return a.includes("text/html") || a.includes("text/markdown");
|
|
12
|
+
}
|
|
13
|
+
async function trackVisit(options) {
|
|
14
|
+
const endpoint = getEndpoint();
|
|
15
|
+
if (!endpoint) {
|
|
16
|
+
return { ok: true, skipped: "disabled" };
|
|
17
|
+
}
|
|
18
|
+
if (!shouldTrack(options.accept)) {
|
|
19
|
+
return { ok: true, skipped: "not-page-view" };
|
|
20
|
+
}
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(endpoint, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: { "Content-Type": "application/json" },
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
host: options.host,
|
|
29
|
+
path: options.path,
|
|
30
|
+
user_agent: options.userAgent,
|
|
31
|
+
accept: options.accept,
|
|
32
|
+
country: options.country || "unknown"
|
|
33
|
+
}),
|
|
34
|
+
signal: controller.signal
|
|
35
|
+
});
|
|
36
|
+
clearTimeout(timeoutId);
|
|
37
|
+
return await response.json();
|
|
38
|
+
} catch (e) {
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
return { ok: false, error: e instanceof Error ? e.message : "unknown error" };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
trackVisit
|
|
46
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface TrackOptions {
|
|
2
|
+
host: string;
|
|
3
|
+
path: string;
|
|
4
|
+
userAgent: string;
|
|
5
|
+
accept: string;
|
|
6
|
+
country?: string;
|
|
7
|
+
}
|
|
8
|
+
interface TrackResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
category?: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
skipped?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function trackVisit(options: TrackOptions): Promise<TrackResult>;
|
|
16
|
+
|
|
17
|
+
export { type TrackOptions, type TrackResult, trackVisit };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface TrackOptions {
|
|
2
|
+
host: string;
|
|
3
|
+
path: string;
|
|
4
|
+
userAgent: string;
|
|
5
|
+
accept: string;
|
|
6
|
+
country?: string;
|
|
7
|
+
}
|
|
8
|
+
interface TrackResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
category?: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
skipped?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function trackVisit(options: TrackOptions): Promise<TrackResult>;
|
|
16
|
+
|
|
17
|
+
export { type TrackOptions, type TrackResult, trackVisit };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
trackVisit: () => trackVisit
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var DEFAULT_ENDPOINT = "https://ai-docs-analytics-api.theisease.workers.dev/track";
|
|
27
|
+
var TIMEOUT_MS = 2500;
|
|
28
|
+
function getEndpoint() {
|
|
29
|
+
const env = typeof process !== "undefined" ? process.env.AI_ANALYTICS_ENDPOINT : void 0;
|
|
30
|
+
if (env === "") return null;
|
|
31
|
+
return env || DEFAULT_ENDPOINT;
|
|
32
|
+
}
|
|
33
|
+
function shouldTrack(accept) {
|
|
34
|
+
const a = accept.toLowerCase();
|
|
35
|
+
return a.includes("text/html") || a.includes("text/markdown");
|
|
36
|
+
}
|
|
37
|
+
async function trackVisit(options) {
|
|
38
|
+
const endpoint = getEndpoint();
|
|
39
|
+
if (!endpoint) {
|
|
40
|
+
return { ok: true, skipped: "disabled" };
|
|
41
|
+
}
|
|
42
|
+
if (!shouldTrack(options.accept)) {
|
|
43
|
+
return { ok: true, skipped: "not-page-view" };
|
|
44
|
+
}
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(endpoint, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
host: options.host,
|
|
53
|
+
path: options.path,
|
|
54
|
+
user_agent: options.userAgent,
|
|
55
|
+
accept: options.accept,
|
|
56
|
+
country: options.country || "unknown"
|
|
57
|
+
}),
|
|
58
|
+
signal: controller.signal
|
|
59
|
+
});
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
return await response.json();
|
|
62
|
+
} catch (e) {
|
|
63
|
+
clearTimeout(timeoutId);
|
|
64
|
+
return { ok: false, error: e instanceof Error ? e.message : "unknown error" };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
trackVisit
|
|
70
|
+
});
|
package/dist/index.mjs
ADDED
package/dist/next.d.mts
ADDED
package/dist/next.d.ts
ADDED
package/dist/next.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/next.ts
|
|
21
|
+
var next_exports = {};
|
|
22
|
+
__export(next_exports, {
|
|
23
|
+
trackVisit: () => trackVisit,
|
|
24
|
+
withAIAnalytics: () => withAIAnalytics
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(next_exports);
|
|
27
|
+
var import_server = require("next/server");
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var DEFAULT_ENDPOINT = "https://ai-docs-analytics-api.theisease.workers.dev/track";
|
|
31
|
+
var TIMEOUT_MS = 2500;
|
|
32
|
+
function getEndpoint() {
|
|
33
|
+
const env = typeof process !== "undefined" ? process.env.AI_ANALYTICS_ENDPOINT : void 0;
|
|
34
|
+
if (env === "") return null;
|
|
35
|
+
return env || DEFAULT_ENDPOINT;
|
|
36
|
+
}
|
|
37
|
+
function shouldTrack(accept) {
|
|
38
|
+
const a = accept.toLowerCase();
|
|
39
|
+
return a.includes("text/html") || a.includes("text/markdown");
|
|
40
|
+
}
|
|
41
|
+
async function trackVisit(options) {
|
|
42
|
+
const endpoint = getEndpoint();
|
|
43
|
+
if (!endpoint) {
|
|
44
|
+
return { ok: true, skipped: "disabled" };
|
|
45
|
+
}
|
|
46
|
+
if (!shouldTrack(options.accept)) {
|
|
47
|
+
return { ok: true, skipped: "not-page-view" };
|
|
48
|
+
}
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetch(endpoint, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: { "Content-Type": "application/json" },
|
|
55
|
+
body: JSON.stringify({
|
|
56
|
+
host: options.host,
|
|
57
|
+
path: options.path,
|
|
58
|
+
user_agent: options.userAgent,
|
|
59
|
+
accept: options.accept,
|
|
60
|
+
country: options.country || "unknown"
|
|
61
|
+
}),
|
|
62
|
+
signal: controller.signal
|
|
63
|
+
});
|
|
64
|
+
clearTimeout(timeoutId);
|
|
65
|
+
return await response.json();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
return { ok: false, error: e instanceof Error ? e.message : "unknown error" };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/next.ts
|
|
73
|
+
function withAIAnalytics(middleware) {
|
|
74
|
+
return async (request, event) => {
|
|
75
|
+
const response = middleware ? await middleware(request, event) : import_server.NextResponse.next();
|
|
76
|
+
trackVisit({
|
|
77
|
+
host: request.headers.get("host") || request.nextUrl.host,
|
|
78
|
+
path: request.nextUrl.pathname,
|
|
79
|
+
userAgent: request.headers.get("user-agent") || "",
|
|
80
|
+
accept: request.headers.get("accept") || "",
|
|
81
|
+
country: request.geo?.country || "unknown"
|
|
82
|
+
}).catch(() => {
|
|
83
|
+
});
|
|
84
|
+
return response;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
trackVisit,
|
|
90
|
+
withAIAnalytics
|
|
91
|
+
});
|
package/dist/next.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
trackVisit
|
|
3
|
+
} from "./chunk-Z3U3YF4H.mjs";
|
|
4
|
+
|
|
5
|
+
// src/next.ts
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
function withAIAnalytics(middleware) {
|
|
8
|
+
return async (request, event) => {
|
|
9
|
+
const response = middleware ? await middleware(request, event) : NextResponse.next();
|
|
10
|
+
trackVisit({
|
|
11
|
+
host: request.headers.get("host") || request.nextUrl.host,
|
|
12
|
+
path: request.nextUrl.pathname,
|
|
13
|
+
userAgent: request.headers.get("user-agent") || "",
|
|
14
|
+
accept: request.headers.get("accept") || "",
|
|
15
|
+
country: request.geo?.country || "unknown"
|
|
16
|
+
}).catch(() => {
|
|
17
|
+
});
|
|
18
|
+
return response;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
trackVisit,
|
|
23
|
+
withAIAnalytics
|
|
24
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "2027-track",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Track AI coding agents visiting your documentation",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/caffeinum/ai-docs-analytics"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/caffeinum/ai-docs-analytics#readme",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/index.mjs",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./next": {
|
|
20
|
+
"types": "./dist/next.d.ts",
|
|
21
|
+
"import": "./dist/next.mjs",
|
|
22
|
+
"require": "./dist/next.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts src/next.ts --format cjs,esm --dts",
|
|
30
|
+
"dev": "tsup src/index.ts src/next.ts --format cjs,esm --dts --watch"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"ai",
|
|
34
|
+
"analytics",
|
|
35
|
+
"middleware",
|
|
36
|
+
"nextjs",
|
|
37
|
+
"vercel",
|
|
38
|
+
"claude",
|
|
39
|
+
"codex",
|
|
40
|
+
"opencode"
|
|
41
|
+
],
|
|
42
|
+
"author": "",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^25.2.1",
|
|
46
|
+
"next": "^14.0.0",
|
|
47
|
+
"tsup": "^8.0.0",
|
|
48
|
+
"typescript": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"next": ">=13.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"next": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|