@aman-sagar06077/zappa-analytics 0.1.4 → 0.1.6
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 +23 -3
- package/crawler.d.ts +1 -1
- package/crawler.js +4 -0
- package/next-crawler.d.ts +16 -22
- package/next-crawler.js +6 -78
- package/package.json +7 -1
- package/web-crawler.d.ts +25 -0
- package/web-crawler.js +91 -0
package/README.md
CHANGED
|
@@ -34,9 +34,28 @@ The SDK defaults to Zappa's hosted collector at `https://www.zappa.in/api/events
|
|
|
34
34
|
|
|
35
35
|
Only initialize analytics when your consent policy permits it. Pass `enabled={false}` to the Next.js component until consent is granted, then render it with `enabled` set to `true`. `init` fails closed without a valid write key. The package tracks initial navigation, History API push/replace, query-only changes and browser back/forward, suppressing duplicate pageviews. It shares a persistent first-party visitor and session hint across tabs; the collector assigns the authoritative session after 30 minutes of inactivity or at a UTC day boundary. Use `analytics.reset()` to start a fresh anonymous identity and `analytics.optOut()` to stop collection and clear identifiers. Events are sent in batches of up to 20 and retried on transient network failures.
|
|
36
36
|
|
|
37
|
-
## AI crawler observations on
|
|
37
|
+
## AI crawler observations on any platform
|
|
38
38
|
|
|
39
|
-
Browser analytics cannot see crawlers that do not execute JavaScript.
|
|
39
|
+
Browser analytics cannot see crawlers that do not execute JavaScript. Crawler observation is free and hosting-neutral, but it must run in a server/edge request hook because browsers do not receive these requests. The package provides a Web Request API for any runtime that supports `Request`, `fetch`, and a background-task callback, plus an Express/Node adapter below. It does not require a specific analytics hosting platform.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { createWebCrawlerCollector } from '@aman-sagar06077/zappa-analytics/web-crawler';
|
|
43
|
+
|
|
44
|
+
const collectCrawler = createWebCrawlerCollector({
|
|
45
|
+
projectId: process.env.ZAPPA_PROJECT_ID,
|
|
46
|
+
crawlerKey: process.env.ZAPPA_CRAWLER_KEY,
|
|
47
|
+
onDiagnostic: (diagnostic) => console.error('[Zappa crawler]', diagnostic.code, diagnostic.statusCode ?? ''),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// In your server/edge request hook, before returning the normal response:
|
|
51
|
+
collectCrawler(request, (task) => executionContext.waitUntil(task));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The callback is runtime-specific (`ctx.waitUntil` on Cloudflare, or `event.waitUntil` in Next.js); the collector itself is not. Keep your existing routing and response logic. Diagnostics identify missing credentials, transport errors, HTTP errors, and scheduling errors without logging the key, IP address, request body, or query string.
|
|
55
|
+
|
|
56
|
+
### Next.js adapter
|
|
57
|
+
|
|
58
|
+
For Next.js, add the adapter to the site's existing `proxy.ts` (Next.js 16+) or `middleware.ts` (older Next.js). Do not replace existing auth, redirects, or rewrites; call the collector and keep the site's existing response logic:
|
|
40
59
|
|
|
41
60
|
```ts
|
|
42
61
|
import { createNextCrawlerProxy } from '@aman-sagar06077/zappa-analytics/next-crawler';
|
|
@@ -44,13 +63,14 @@ import { createNextCrawlerProxy } from '@aman-sagar06077/zappa-analytics/next-cr
|
|
|
44
63
|
const collectZappaCrawlerRequest = createNextCrawlerProxy({
|
|
45
64
|
projectId: process.env.ZAPPA_PROJECT_ID ?? '',
|
|
46
65
|
crawlerKey: process.env.ZAPPA_CRAWLER_KEY ?? '',
|
|
66
|
+
onDiagnostic: ({ code, statusCode }) => console.error('[Zappa crawler]', code, statusCode ?? ''),
|
|
47
67
|
});
|
|
48
68
|
|
|
49
69
|
// Inside your existing proxy/middleware function, before returning its response:
|
|
50
70
|
collectZappaCrawlerRequest(request, event);
|
|
51
71
|
```
|
|
52
72
|
|
|
53
|
-
The Next.js `event` argument keeps the small telemetry request alive after the site response is returned. The collector only reports recognized crawler-like GET/HEAD page requests, removes query strings, sends no IP address, and records status as `0` (unknown) because Proxy runs before the route. It recognizes search crawlers and user-triggered fetchers, including Perplexity-User and Claude-Agent. Extend your existing matcher to include public page routes while excluding static assets and API routes.
|
|
73
|
+
The Next.js `event` argument keeps the small telemetry request alive after the site response is returned. The collector only reports recognized crawler-like GET/HEAD page requests, removes query strings, sends no IP address, and records status as `0` (unknown) because Proxy runs before the route. It recognizes known search crawlers and user-triggered fetchers, including Perplexity-User and Claude-Agent. Unknown user agents that identify themselves with bot, crawler, spider, agent, assistant, or fetcher terms are also reported under generic unverified labels, so new providers do not require a package release just to appear. Extend your existing matcher to include public page routes while excluding static assets and API routes. Set `ZAPPA_PROJECT_ID` and `ZAPPA_CRAWLER_KEY` as server-only environment variables for the site runtime, then redeploy. The key is private: never add a `NEXT_PUBLIC_` prefix or commit it.
|
|
54
74
|
|
|
55
75
|
## AI crawler observations on Node/Express
|
|
56
76
|
|
package/crawler.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type CrawlerMatch = {
|
|
|
9
9
|
crawler: string;
|
|
10
10
|
organization: string;
|
|
11
11
|
category: CrawlerCategory;
|
|
12
|
-
detectionMethod: 'known_user_agent_match' | 'generic_user_agent_match';
|
|
12
|
+
detectionMethod: 'known_user_agent_match' | 'generic_user_agent_match' | 'generic_ai_agent_match';
|
|
13
13
|
verificationStatus: 'unverified';
|
|
14
14
|
};
|
|
15
15
|
|
package/crawler.js
CHANGED
|
@@ -21,6 +21,7 @@ const REGISTRY = [
|
|
|
21
21
|
[/\bCCBot\b/i, 'CCBot', 'Common Crawl', 'unknown_bot'],
|
|
22
22
|
];
|
|
23
23
|
const GENERIC_BOT = /(?:\bbot\b|crawler|spider|crawl|slurp|scrapy|archiver|headlesschrome|phantomjs|puppeteer|playwright|selenium|lighthouse|pagespeed|pingdom|uptime|statuscake|gtmetrix|facebookexternalhit|slackbot|discordbot)/i;
|
|
24
|
+
const GENERIC_AI_AGENT = /\b(?!user-agent\b)[a-z][a-z0-9._-]*(?:agent|assistant|fetcher)\b/i;
|
|
24
25
|
const HOST_LABELS = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
25
26
|
|
|
26
27
|
/** Return a known UA match, explicitly unverified, or null for an ordinary UA. */
|
|
@@ -32,6 +33,9 @@ export function classifyCrawler(userAgent) {
|
|
|
32
33
|
return { crawler, organization, category, detectionMethod: 'known_user_agent_match', verificationStatus: 'unverified' };
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
if (GENERIC_AI_AGENT.test(value)) {
|
|
37
|
+
return { crawler: 'Unknown AI agent', organization: 'Unknown', category: 'ai_assistant_fetcher', detectionMethod: 'generic_ai_agent_match', verificationStatus: 'unverified' };
|
|
38
|
+
}
|
|
35
39
|
if (GENERIC_BOT.test(value)) {
|
|
36
40
|
return { crawler: 'Unknown bot', organization: 'Unknown', category: 'unknown_bot', detectionMethod: 'generic_user_agent_match', verificationStatus: 'unverified' };
|
|
37
41
|
}
|
package/next-crawler.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
export type NextCrawlerRequest = {
|
|
2
|
-
url: string;
|
|
3
|
-
method?: string;
|
|
4
|
-
headers: { get(name: string): string | null };
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type NextCrawlerEvent = {
|
|
8
|
-
waitUntil(promise: Promise<unknown>): void;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type NextCrawlerOptions =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Create an Edge-safe collector for Next.js Proxy or Middleware request events. */
|
|
20
|
-
export function createNextCrawlerProxy(
|
|
21
|
-
options: NextCrawlerOptions,
|
|
22
|
-
): (request: NextCrawlerRequest, event: NextCrawlerEvent) => boolean;
|
|
1
|
+
export type NextCrawlerRequest = {
|
|
2
|
+
url: string;
|
|
3
|
+
method?: string;
|
|
4
|
+
headers: { get(name: string): string | null };
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type NextCrawlerEvent = {
|
|
8
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type NextCrawlerOptions = import('./web-crawler.js').WebCrawlerCollectorOptions;
|
|
12
|
+
|
|
13
|
+
/** Create an Edge-safe collector for Next.js Proxy or Middleware request events. */
|
|
14
|
+
export function createNextCrawlerProxy(
|
|
15
|
+
options: NextCrawlerOptions,
|
|
16
|
+
): (request: NextCrawlerRequest, event: NextCrawlerEvent) => boolean;
|
package/next-crawler.js
CHANGED
|
@@ -1,82 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const DEFAULT_ENDPOINT = 'https://www.zappa.in/api/ai-crawlers';
|
|
4
|
-
const PRIVATE_KEY = /^ZappaCrawler_[A-Za-z0-9_-]{32,}$/;
|
|
5
|
-
const HOST_LABELS = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
6
|
-
const NON_PAGE_PATH = /(?:^\/_next\/|^\/api\/|\.(?:avif|bmp|css|gif|ico|jpe?g|js|map|mjs|png|svg|webp|woff2?|ttf|eot|pdf|zip|xml)$)/i;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Create an Edge-safe collector for Next.js Proxy (or Middleware on older Next.js).
|
|
10
|
-
* Call it with the incoming Request and NextFetchEvent; it only schedules work for
|
|
11
|
-
* recognized crawler-like GET/HEAD requests and never changes the page response.
|
|
12
|
-
*/
|
|
13
|
-
export function createNextCrawlerProxy({
|
|
14
|
-
projectId,
|
|
15
|
-
crawlerKey,
|
|
16
|
-
endpoint = DEFAULT_ENDPOINT,
|
|
17
|
-
fetchImpl = globalThis.fetch,
|
|
18
|
-
timeoutMs = 800,
|
|
19
|
-
} = {}) {
|
|
20
|
-
// Keep collection optional in local/preview environments where secrets are absent.
|
|
21
|
-
if (!projectId || !crawlerKey) return () => false;
|
|
22
|
-
if (typeof projectId !== 'string' || !projectId.trim()) throw new TypeError('projectId is required');
|
|
23
|
-
if (typeof crawlerKey !== 'string' || !PRIVATE_KEY.test(crawlerKey)) throw new TypeError('A private Zappa crawler key is required');
|
|
24
|
-
if (typeof fetchImpl !== 'function') throw new TypeError('Fetch is required');
|
|
25
|
-
|
|
26
|
-
const target = new URL(endpoint);
|
|
27
|
-
if (target.protocol !== 'https:' && target.hostname !== 'localhost') throw new TypeError('The crawler endpoint must use HTTPS');
|
|
28
|
-
const safeTimeout = Math.max(100, Math.min(Number(timeoutMs) || 800, 3000));
|
|
1
|
+
import { createWebCrawlerCollector } from './web-crawler.js';
|
|
29
2
|
|
|
3
|
+
/** Create a Next.js adapter over the hosting-neutral Web Request collector. */
|
|
4
|
+
export function createNextCrawlerProxy(options = {}) {
|
|
5
|
+
const collect = createWebCrawlerCollector(options);
|
|
30
6
|
return function collectNextCrawlerRequest(request, event) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const method = String(request.method || 'GET').toUpperCase();
|
|
35
|
-
if (method !== 'GET' && method !== 'HEAD') return false;
|
|
36
|
-
|
|
37
|
-
let url;
|
|
38
|
-
try {
|
|
39
|
-
url = new URL(request.url);
|
|
40
|
-
} catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const path = url.pathname;
|
|
44
|
-
if (!HOST_LABELS.test(url.hostname) || !path.startsWith('/') || path.length > 512 || NON_PAGE_PATH.test(path)) return false;
|
|
45
|
-
if (!event || typeof event.waitUntil !== 'function' || typeof globalThis.crypto?.randomUUID !== 'function') return false;
|
|
46
|
-
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
const timeout = setTimeout(() => controller.abort(), safeTimeout);
|
|
49
|
-
const payload = {
|
|
50
|
-
projectId,
|
|
51
|
-
requests: [{
|
|
52
|
-
requestId: globalThis.crypto.randomUUID(),
|
|
53
|
-
timestamp: new Date().toISOString(),
|
|
54
|
-
hostname: url.hostname.toLowerCase().replace(/\.$/, ''),
|
|
55
|
-
path,
|
|
56
|
-
method,
|
|
57
|
-
// Proxy runs before the route, so the final HTTP status is not observable here.
|
|
58
|
-
// 0 is the API's documented sentinel for a status unavailable in Proxy.
|
|
59
|
-
statusCode: 0,
|
|
60
|
-
userAgent,
|
|
61
|
-
}],
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const task = Promise.resolve()
|
|
65
|
-
.then(() => fetchImpl(target, {
|
|
66
|
-
method: 'POST',
|
|
67
|
-
headers: { 'Content-Type': 'application/json', 'X-Zappa-Crawler-Key': crawlerKey },
|
|
68
|
-
body: JSON.stringify(payload),
|
|
69
|
-
signal: controller.signal,
|
|
70
|
-
}))
|
|
71
|
-
.catch(() => {})
|
|
72
|
-
.finally(() => clearTimeout(timeout));
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
event.waitUntil(task);
|
|
76
|
-
return true;
|
|
77
|
-
} catch {
|
|
78
|
-
// Telemetry must never break or delay the site's page response.
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
7
|
+
if (!event || typeof event.waitUntil !== 'function') return false;
|
|
8
|
+
return collect(request, (task) => event.waitUntil(task));
|
|
81
9
|
};
|
|
82
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aman-sagar06077/zappa-analytics",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Privacy-aware website analytics for Zappa projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"./next-crawler": {
|
|
22
22
|
"types": "./next-crawler.d.ts",
|
|
23
23
|
"default": "./next-crawler.js"
|
|
24
|
+
},
|
|
25
|
+
"./web-crawler": {
|
|
26
|
+
"types": "./web-crawler.d.ts",
|
|
27
|
+
"default": "./web-crawler.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
@@ -32,6 +36,8 @@
|
|
|
32
36
|
"crawler.d.ts",
|
|
33
37
|
"next-crawler.js",
|
|
34
38
|
"next-crawler.d.ts",
|
|
39
|
+
"web-crawler.js",
|
|
40
|
+
"web-crawler.d.ts",
|
|
35
41
|
"README.md"
|
|
36
42
|
],
|
|
37
43
|
"peerDependencies": {
|
package/web-crawler.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type WebCrawlerRequest = {
|
|
2
|
+
url: string;
|
|
3
|
+
method?: string;
|
|
4
|
+
headers: { get(name: string): string | null };
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type CrawlerDiagnostic = {
|
|
8
|
+
code: 'missing_credentials' | 'collector_http_error' | 'collector_transport_error' | 'schedule_failed';
|
|
9
|
+
statusCode?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type WebCrawlerCollectorOptions = {
|
|
13
|
+
projectId?: string;
|
|
14
|
+
crawlerKey?: string;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
fetchImpl?: (input: URL, init: Record<string, unknown>) => Promise<unknown>;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** Optional safe diagnostic hook. Values never include secrets or request data. */
|
|
19
|
+
onDiagnostic?: (diagnostic: CrawlerDiagnostic) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Create a Web Request collector usable from any hosting/runtime request hook. */
|
|
23
|
+
export function createWebCrawlerCollector(
|
|
24
|
+
options?: WebCrawlerCollectorOptions,
|
|
25
|
+
): (request: WebCrawlerRequest, schedule: (task: Promise<unknown>) => void) => boolean;
|
package/web-crawler.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { classifyCrawler } from './crawler.js';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_ENDPOINT = 'https://www.zappa.in/api/ai-crawlers';
|
|
4
|
+
const PRIVATE_KEY = /^ZappaCrawler_[A-Za-z0-9_-]{32,}$/;
|
|
5
|
+
const HOST_LABELS = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
6
|
+
const NON_PAGE_PATH = /(?:^\/_next\/|^\/api\/|\.(?:avif|bmp|css|gif|ico|jpe?g|js|map|mjs|png|svg|webp|woff2?|ttf|eot|pdf|zip|xml)$)/i;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Build a framework-neutral collector for Web Request runtimes. The host calls
|
|
10
|
+
* it from its request hook and passes a callback that keeps `task` alive after
|
|
11
|
+
* the response, such as Cloudflare's ctx.waitUntil or Next's event.waitUntil.
|
|
12
|
+
* Diagnostics contain codes/status only and never include credentials, bodies,
|
|
13
|
+
* IP addresses, query strings, or full URLs.
|
|
14
|
+
*/
|
|
15
|
+
export function createWebCrawlerCollector({
|
|
16
|
+
projectId,
|
|
17
|
+
crawlerKey,
|
|
18
|
+
endpoint = DEFAULT_ENDPOINT,
|
|
19
|
+
fetchImpl = globalThis.fetch,
|
|
20
|
+
timeoutMs = 800,
|
|
21
|
+
onDiagnostic,
|
|
22
|
+
} = {}) {
|
|
23
|
+
const diagnose = (code, statusCode) => {
|
|
24
|
+
if (typeof onDiagnostic !== 'function') return;
|
|
25
|
+
try { onDiagnostic(statusCode === undefined ? { code } : { code, statusCode }); } catch { /* Diagnostics must not affect requests. */ }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Make missing production configuration observable without breaking the site.
|
|
29
|
+
if (!projectId || !crawlerKey) {
|
|
30
|
+
diagnose('missing_credentials');
|
|
31
|
+
return () => false;
|
|
32
|
+
}
|
|
33
|
+
if (typeof projectId !== 'string' || !projectId.trim()) throw new TypeError('projectId is required');
|
|
34
|
+
if (typeof crawlerKey !== 'string' || !PRIVATE_KEY.test(crawlerKey)) throw new TypeError('A private Zappa crawler key is required');
|
|
35
|
+
if (typeof fetchImpl !== 'function') throw new TypeError('Fetch is required');
|
|
36
|
+
|
|
37
|
+
const target = new URL(endpoint);
|
|
38
|
+
if (target.protocol !== 'https:' && target.hostname !== 'localhost') throw new TypeError('The crawler endpoint must use HTTPS');
|
|
39
|
+
const safeTimeout = Math.max(100, Math.min(Number(timeoutMs) || 800, 3000));
|
|
40
|
+
|
|
41
|
+
return function collectWebCrawlerRequest(request, schedule) {
|
|
42
|
+
const userAgent = request?.headers?.get?.('user-agent')?.slice(0, 1024) ?? '';
|
|
43
|
+
if (!classifyCrawler(userAgent)) return false;
|
|
44
|
+
|
|
45
|
+
const method = String(request.method || 'GET').toUpperCase();
|
|
46
|
+
if (method !== 'GET' && method !== 'HEAD') return false;
|
|
47
|
+
|
|
48
|
+
let url;
|
|
49
|
+
try { url = new URL(request.url); } catch { return false; }
|
|
50
|
+
const path = url.pathname;
|
|
51
|
+
if (!HOST_LABELS.test(url.hostname) || !path.startsWith('/') || path.length > 512 || NON_PAGE_PATH.test(path)) return false;
|
|
52
|
+
if (typeof schedule !== 'function' || typeof globalThis.crypto?.randomUUID !== 'function') return false;
|
|
53
|
+
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
const timeout = setTimeout(() => controller.abort(), safeTimeout);
|
|
56
|
+
const payload = {
|
|
57
|
+
projectId,
|
|
58
|
+
requests: [{
|
|
59
|
+
requestId: globalThis.crypto.randomUUID(),
|
|
60
|
+
timestamp: new Date().toISOString(),
|
|
61
|
+
hostname: url.hostname.toLowerCase().replace(/\.$/, ''),
|
|
62
|
+
path,
|
|
63
|
+
method,
|
|
64
|
+
statusCode: 0,
|
|
65
|
+
userAgent,
|
|
66
|
+
}],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const task = Promise.resolve()
|
|
70
|
+
.then(() => fetchImpl(target, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: { 'Content-Type': 'application/json', 'X-Zappa-Crawler-Key': crawlerKey },
|
|
73
|
+
body: JSON.stringify(payload),
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
}))
|
|
76
|
+
.then((response) => {
|
|
77
|
+
if (typeof response?.status === 'number' && response.status >= 400) diagnose('collector_http_error', response.status);
|
|
78
|
+
})
|
|
79
|
+
.catch(() => diagnose('collector_transport_error'))
|
|
80
|
+
.finally(() => clearTimeout(timeout));
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
schedule(task);
|
|
84
|
+
return true;
|
|
85
|
+
} catch {
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
diagnose('schedule_failed');
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|