@d-zero/beholder 2.1.6 → 3.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/CHANGELOG.md +44 -0
- package/README.md +26 -0
- package/dist/dom-evaluation.d.ts +72 -24
- package/dist/dom-evaluation.js +310 -84
- package/dist/extract-meta.d.ts +98 -0
- package/dist/extract-meta.js +75 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/meta/classify.d.ts +52 -0
- package/dist/meta/classify.js +731 -0
- package/dist/meta/collect-head.d.ts +63 -0
- package/dist/meta/collect-head.js +223 -0
- package/dist/meta/id-extractors.d.ts +40 -0
- package/dist/meta/id-extractors.js +196 -0
- package/dist/meta/keys.d.ts +41 -0
- package/dist/meta/keys.js +507 -0
- package/dist/meta/parsers.d.ts +74 -0
- package/dist/meta/parsers.js +293 -0
- package/dist/meta/tag-detection.d.ts +59 -0
- package/dist/meta/tag-detection.js +120 -0
- package/dist/meta/types.d.ts +874 -0
- package/dist/meta/types.js +12 -0
- package/dist/scraper.js +15 -13
- package/dist/types.d.ts +3 -38
- package/package.json +8 -5
- package/src/dom-evaluation.spec.ts +301 -73
- package/src/dom-evaluation.ts +417 -88
- package/src/extract-meta.spec.ts +247 -0
- package/src/extract-meta.ts +121 -0
- package/src/index.ts +45 -0
- package/src/meta/classify.spec.ts +281 -0
- package/src/meta/classify.ts +810 -0
- package/src/meta/collect-head.ts +247 -0
- package/src/meta/id-extractors.spec.ts +69 -0
- package/src/meta/id-extractors.ts +206 -0
- package/src/meta/keys.ts +568 -0
- package/src/meta/parsers.spec.ts +178 -0
- package/src/meta/parsers.ts +304 -0
- package/src/meta/simple-wappalyzer.d.ts +37 -0
- package/src/meta/tag-detection.spec.ts +134 -0
- package/src/meta/tag-detection.ts +161 -0
- package/src/meta/types.ts +949 -0
- package/src/scraper.ts +19 -13
- package/src/types.ts +49 -55
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-side raw `<head>` collector.
|
|
3
|
+
*
|
|
4
|
+
* `collectHeadFromDocument` walks a `Document` (Puppeteer page realm or jsdom realm
|
|
5
|
+
* alike) and produces a serializable {@link RawHeadEntry}[] that
|
|
6
|
+
* {@link ../meta/classify.ts | classify} can turn into a typed `Meta`.
|
|
7
|
+
*
|
|
8
|
+
* WHY this function is realm-agnostic:
|
|
9
|
+
*
|
|
10
|
+
* - The Puppeteer path stringifies this function via `Function.prototype.toString`
|
|
11
|
+
* and runs it as a `page.evaluate(string)` expression, so any closure over
|
|
12
|
+
* module-scope bindings would resolve to `undefined` in the browser realm.
|
|
13
|
+
* - The jsdom (Node) path calls it directly with the jsdom `Window`. Because
|
|
14
|
+
* `HTMLLinkElement` (etc.) in jsdom is a *different class instance* from the
|
|
15
|
+
* one in the page realm, `instanceof` only works when the constructor is read
|
|
16
|
+
* from the *passed* `window` rather than from bare globals.
|
|
17
|
+
*
|
|
18
|
+
* Together those constraints dictate that the function MUST:
|
|
19
|
+
*
|
|
20
|
+
* 1. Reference no module-level variables — only its own parameters and inner locals.
|
|
21
|
+
* 2. Take every HTML class constructor (`HTMLBaseElement`, …) from the passed
|
|
22
|
+
* `window` via destructuring instead of relying on ambient globals.
|
|
23
|
+
* 3. Stay in plain ES syntax (no TS-only constructs that need helper imports).
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import type { RawHeadEntry } from './types.js';
|
|
27
|
+
/**
|
|
28
|
+
* Curated list of `window` globals whose presence indicates that a third-party
|
|
29
|
+
* tag library has been loaded on the page. Surfaced as a single
|
|
30
|
+
* `kind: 'window-global'` entry so that downstream consumers (e.g. tag-detection)
|
|
31
|
+
* can cross-reference the script/iframe signals.
|
|
32
|
+
*
|
|
33
|
+
* Kept here (rather than in `dom-evaluation.ts`) so the Puppeteer path and the
|
|
34
|
+
* jsdom path share one source of truth.
|
|
35
|
+
*/
|
|
36
|
+
export declare const WINDOW_GLOBALS_TO_CHECK: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Walks the given window's `Document` and returns a serializable list of raw
|
|
39
|
+
* head entries.
|
|
40
|
+
*
|
|
41
|
+
* Two realms are supported:
|
|
42
|
+
*
|
|
43
|
+
* - Browser realm (Puppeteer): the function source is `.toString()`'d and run
|
|
44
|
+
* inside the page via `page.evaluate(string)`. Inside the page, `window`
|
|
45
|
+
* resolves to the page's global object, so destructured class constructors
|
|
46
|
+
* match `instanceof` checks against elements returned from `querySelectorAll`.
|
|
47
|
+
* - Node realm (jsdom et al.): the caller passes `dom.window` directly. jsdom's
|
|
48
|
+
* HTML element prototypes are distinct from the host Node's bare globals, so
|
|
49
|
+
* reading the constructors off the passed `window` is what makes `instanceof`
|
|
50
|
+
* succeed.
|
|
51
|
+
*
|
|
52
|
+
* The function MUST NOT close over any module-scope binding — all data it needs
|
|
53
|
+
* is reached through its two parameters.
|
|
54
|
+
* @param window - The window object whose `document` will be inspected. Provides
|
|
55
|
+
* both the DOM tree and the HTML element constructors used for
|
|
56
|
+
* `instanceof` narrowing.
|
|
57
|
+
* @param knownGlobals - Names of `window` properties that, when present,
|
|
58
|
+
* indicate a third-party tag library is loaded. Required
|
|
59
|
+
* (no default) so the Puppeteer-side string-eval path
|
|
60
|
+
* does not have to inline a default value list.
|
|
61
|
+
* @returns Serializable list of raw head entries for {@link ../meta/classify.ts | classify}.
|
|
62
|
+
*/
|
|
63
|
+
export declare function collectHeadFromDocument(window: Window, knownGlobals: readonly string[]): RawHeadEntry[];
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-side raw `<head>` collector.
|
|
3
|
+
*
|
|
4
|
+
* `collectHeadFromDocument` walks a `Document` (Puppeteer page realm or jsdom realm
|
|
5
|
+
* alike) and produces a serializable {@link RawHeadEntry}[] that
|
|
6
|
+
* {@link ../meta/classify.ts | classify} can turn into a typed `Meta`.
|
|
7
|
+
*
|
|
8
|
+
* WHY this function is realm-agnostic:
|
|
9
|
+
*
|
|
10
|
+
* - The Puppeteer path stringifies this function via `Function.prototype.toString`
|
|
11
|
+
* and runs it as a `page.evaluate(string)` expression, so any closure over
|
|
12
|
+
* module-scope bindings would resolve to `undefined` in the browser realm.
|
|
13
|
+
* - The jsdom (Node) path calls it directly with the jsdom `Window`. Because
|
|
14
|
+
* `HTMLLinkElement` (etc.) in jsdom is a *different class instance* from the
|
|
15
|
+
* one in the page realm, `instanceof` only works when the constructor is read
|
|
16
|
+
* from the *passed* `window` rather than from bare globals.
|
|
17
|
+
*
|
|
18
|
+
* Together those constraints dictate that the function MUST:
|
|
19
|
+
*
|
|
20
|
+
* 1. Reference no module-level variables — only its own parameters and inner locals.
|
|
21
|
+
* 2. Take every HTML class constructor (`HTMLBaseElement`, …) from the passed
|
|
22
|
+
* `window` via destructuring instead of relying on ambient globals.
|
|
23
|
+
* 3. Stay in plain ES syntax (no TS-only constructs that need helper imports).
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Curated list of `window` globals whose presence indicates that a third-party
|
|
28
|
+
* tag library has been loaded on the page. Surfaced as a single
|
|
29
|
+
* `kind: 'window-global'` entry so that downstream consumers (e.g. tag-detection)
|
|
30
|
+
* can cross-reference the script/iframe signals.
|
|
31
|
+
*
|
|
32
|
+
* Kept here (rather than in `dom-evaluation.ts`) so the Puppeteer path and the
|
|
33
|
+
* jsdom path share one source of truth.
|
|
34
|
+
*/
|
|
35
|
+
export const WINDOW_GLOBALS_TO_CHECK = [
|
|
36
|
+
'dataLayer',
|
|
37
|
+
'gtag',
|
|
38
|
+
'ga',
|
|
39
|
+
'_gaq',
|
|
40
|
+
'fbq',
|
|
41
|
+
'_fbq',
|
|
42
|
+
'clarity',
|
|
43
|
+
'_hjSettings',
|
|
44
|
+
'_hjid',
|
|
45
|
+
'twq',
|
|
46
|
+
'ttq',
|
|
47
|
+
'_linkedin_partner_id',
|
|
48
|
+
'pintrk',
|
|
49
|
+
'amplitude',
|
|
50
|
+
'mixpanel',
|
|
51
|
+
'analytics',
|
|
52
|
+
'heap',
|
|
53
|
+
'posthog',
|
|
54
|
+
'plausible',
|
|
55
|
+
'fathom',
|
|
56
|
+
'_paq',
|
|
57
|
+
's_account',
|
|
58
|
+
's',
|
|
59
|
+
'ym',
|
|
60
|
+
'UET',
|
|
61
|
+
'optimizely',
|
|
62
|
+
'_hsq',
|
|
63
|
+
'Sentry',
|
|
64
|
+
'Intercom',
|
|
65
|
+
'intercomSettings',
|
|
66
|
+
'drift',
|
|
67
|
+
'Tawk_API',
|
|
68
|
+
'zE',
|
|
69
|
+
'OneTrust',
|
|
70
|
+
'Cookiebot',
|
|
71
|
+
'Stripe',
|
|
72
|
+
'grecaptcha',
|
|
73
|
+
];
|
|
74
|
+
/**
|
|
75
|
+
* Walks the given window's `Document` and returns a serializable list of raw
|
|
76
|
+
* head entries.
|
|
77
|
+
*
|
|
78
|
+
* Two realms are supported:
|
|
79
|
+
*
|
|
80
|
+
* - Browser realm (Puppeteer): the function source is `.toString()`'d and run
|
|
81
|
+
* inside the page via `page.evaluate(string)`. Inside the page, `window`
|
|
82
|
+
* resolves to the page's global object, so destructured class constructors
|
|
83
|
+
* match `instanceof` checks against elements returned from `querySelectorAll`.
|
|
84
|
+
* - Node realm (jsdom et al.): the caller passes `dom.window` directly. jsdom's
|
|
85
|
+
* HTML element prototypes are distinct from the host Node's bare globals, so
|
|
86
|
+
* reading the constructors off the passed `window` is what makes `instanceof`
|
|
87
|
+
* succeed.
|
|
88
|
+
*
|
|
89
|
+
* The function MUST NOT close over any module-scope binding — all data it needs
|
|
90
|
+
* is reached through its two parameters.
|
|
91
|
+
* @param window - The window object whose `document` will be inspected. Provides
|
|
92
|
+
* both the DOM tree and the HTML element constructors used for
|
|
93
|
+
* `instanceof` narrowing.
|
|
94
|
+
* @param knownGlobals - Names of `window` properties that, when present,
|
|
95
|
+
* indicate a third-party tag library is loaded. Required
|
|
96
|
+
* (no default) so the Puppeteer-side string-eval path
|
|
97
|
+
* does not have to inline a default value list.
|
|
98
|
+
* @returns Serializable list of raw head entries for {@link ../meta/classify.ts | classify}.
|
|
99
|
+
*/
|
|
100
|
+
export function collectHeadFromDocument(window, knownGlobals) {
|
|
101
|
+
const document = window.document;
|
|
102
|
+
// TypeScript's `Window` interface in lib.dom does not directly expose the
|
|
103
|
+
// HTML element constructors (`HTMLLinkElement`, `HTMLScriptElement`, …)
|
|
104
|
+
// even though every real window object — browser realm AND jsdom realm —
|
|
105
|
+
// carries them at runtime. Widening the type here lets us destructure them
|
|
106
|
+
// uniformly; the runtime values come straight from the passed window, so
|
|
107
|
+
// the cast is purely cosmetic for TS and erased at compile time.
|
|
108
|
+
const w = window;
|
|
109
|
+
const { HTMLBaseElement, HTMLMetaElement, HTMLLinkElement, HTMLScriptElement, HTMLIFrameElement, } = w;
|
|
110
|
+
const entries = [];
|
|
111
|
+
const html = document.documentElement;
|
|
112
|
+
entries.push({
|
|
113
|
+
kind: 'html',
|
|
114
|
+
lang: html.lang || undefined,
|
|
115
|
+
dir: html.dir || undefined,
|
|
116
|
+
xmlns: html.getAttribute('xmlns') ?? undefined,
|
|
117
|
+
prefix: html.getAttribute('prefix') ?? undefined,
|
|
118
|
+
vocab: html.getAttribute('vocab') ?? undefined,
|
|
119
|
+
typeOf: html.getAttribute('typeof') ?? undefined,
|
|
120
|
+
itemscope: html.hasAttribute('itemscope') || undefined,
|
|
121
|
+
itemtype: html.getAttribute('itemtype') ?? undefined,
|
|
122
|
+
amp: html.hasAttribute('amp') || undefined,
|
|
123
|
+
lightning: html.hasAttribute('⚡') || undefined,
|
|
124
|
+
}, { kind: 'title', content: document.title });
|
|
125
|
+
for (const base of document.querySelectorAll('base')) {
|
|
126
|
+
if (!(base instanceof HTMLBaseElement))
|
|
127
|
+
continue;
|
|
128
|
+
entries.push({
|
|
129
|
+
kind: 'base',
|
|
130
|
+
href: base.getAttribute('href') ?? undefined,
|
|
131
|
+
target: base.getAttribute('target') ?? undefined,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
for (const meta of document.querySelectorAll('meta')) {
|
|
135
|
+
if (!(meta instanceof HTMLMetaElement))
|
|
136
|
+
continue;
|
|
137
|
+
const name = meta.getAttribute('name');
|
|
138
|
+
const property = meta.getAttribute('property');
|
|
139
|
+
const httpEquiv = meta.getAttribute('http-equiv');
|
|
140
|
+
const itemprop = meta.getAttribute('itemprop');
|
|
141
|
+
const charset = meta.getAttribute('charset');
|
|
142
|
+
const content = meta.getAttribute('content');
|
|
143
|
+
const media = meta.getAttribute('media');
|
|
144
|
+
entries.push({
|
|
145
|
+
kind: 'meta',
|
|
146
|
+
name: name ? name.toLowerCase() : undefined,
|
|
147
|
+
property: property ? property.toLowerCase() : undefined,
|
|
148
|
+
httpEquiv: httpEquiv ? httpEquiv.toLowerCase() : undefined,
|
|
149
|
+
itemprop: itemprop ?? undefined,
|
|
150
|
+
charset: charset ?? undefined,
|
|
151
|
+
content: content ?? undefined,
|
|
152
|
+
media: media ?? undefined,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
for (const link of document.querySelectorAll('link[href]')) {
|
|
156
|
+
if (!(link instanceof HTMLLinkElement))
|
|
157
|
+
continue;
|
|
158
|
+
const relRaw = link.getAttribute('rel') ?? '';
|
|
159
|
+
const rel = relRaw.toLowerCase().split(/\s+/u).filter(Boolean);
|
|
160
|
+
entries.push({
|
|
161
|
+
kind: 'link',
|
|
162
|
+
rel,
|
|
163
|
+
href: link.getAttribute('href') ?? '',
|
|
164
|
+
type: link.getAttribute('type') ?? undefined,
|
|
165
|
+
media: link.getAttribute('media') ?? undefined,
|
|
166
|
+
sizes: link.getAttribute('sizes') ?? undefined,
|
|
167
|
+
title: link.getAttribute('title') ?? undefined,
|
|
168
|
+
hreflang: link.getAttribute('hreflang') ?? undefined,
|
|
169
|
+
as: link.getAttribute('as') ?? undefined,
|
|
170
|
+
crossorigin: link.getAttribute('crossorigin') ?? undefined,
|
|
171
|
+
color: link.getAttribute('color') ?? undefined,
|
|
172
|
+
blocking: link.getAttribute('blocking') ?? undefined,
|
|
173
|
+
imagesrcset: link.getAttribute('imagesrcset') ?? undefined,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const STRUCTURED_TYPES = new Set([
|
|
177
|
+
'application/ld+json',
|
|
178
|
+
'speculationrules',
|
|
179
|
+
'application/json+oembed',
|
|
180
|
+
'application/xml+oembed',
|
|
181
|
+
]);
|
|
182
|
+
for (const script of document.querySelectorAll('script[type]')) {
|
|
183
|
+
if (!(script instanceof HTMLScriptElement))
|
|
184
|
+
continue;
|
|
185
|
+
const scriptType = (script.getAttribute('type') ?? '').toLowerCase();
|
|
186
|
+
if (!STRUCTURED_TYPES.has(scriptType))
|
|
187
|
+
continue;
|
|
188
|
+
const src = script.getAttribute('src') ?? undefined;
|
|
189
|
+
const text = script.textContent ?? '';
|
|
190
|
+
const inHead = !!script.closest('head');
|
|
191
|
+
const inNoscript = !!script.closest('noscript');
|
|
192
|
+
const location = inHead ? 'head' : inNoscript ? 'noscript' : 'body';
|
|
193
|
+
entries.push({
|
|
194
|
+
kind: 'script',
|
|
195
|
+
scriptType,
|
|
196
|
+
content: text || undefined,
|
|
197
|
+
src,
|
|
198
|
+
location,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
for (const iframe of document.querySelectorAll('iframe[src]')) {
|
|
202
|
+
if (!(iframe instanceof HTMLIFrameElement))
|
|
203
|
+
continue;
|
|
204
|
+
const src = iframe.getAttribute('src') ?? '';
|
|
205
|
+
if (!src)
|
|
206
|
+
continue;
|
|
207
|
+
const inHead = !!iframe.closest('head');
|
|
208
|
+
const inNoscript = !!iframe.closest('noscript');
|
|
209
|
+
const location = inHead ? 'head' : inNoscript ? 'noscript' : 'body';
|
|
210
|
+
entries.push({ kind: 'iframe', src, location });
|
|
211
|
+
}
|
|
212
|
+
const win = window;
|
|
213
|
+
const presentGlobals = [];
|
|
214
|
+
for (const name of knownGlobals) {
|
|
215
|
+
if (win[name] !== undefined) {
|
|
216
|
+
presentGlobals.push(name);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (presentGlobals.length > 0) {
|
|
220
|
+
entries.push({ kind: 'window-global', names: presentGlobals });
|
|
221
|
+
}
|
|
222
|
+
return entries;
|
|
223
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific real-ID extraction rules.
|
|
3
|
+
*
|
|
4
|
+
* `simple-wappalyzer` identifies the *technology* (e.g., "Google Analytics") but
|
|
5
|
+
* does not surface the actual account/measurement ID. We layer real-ID
|
|
6
|
+
* extraction on top: for each detected provider, apply the registered regex
|
|
7
|
+
* over the page HTML and surface what we find.
|
|
8
|
+
*
|
|
9
|
+
* Provider keys must match the names produced by `simple-wappalyzer` exactly;
|
|
10
|
+
* these in turn track `wappalyzer-core@6` (the MIT-licensed fingerprint set).
|
|
11
|
+
*
|
|
12
|
+
* Keep the table **manually maintained**, not generated from Wappalyzer data.
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
export type IdExtractor = {
|
|
16
|
+
/**
|
|
17
|
+
* Each regex MUST contain at most one capturing group; the captured text
|
|
18
|
+
* becomes the ID. Patterns without a capturing group fall back to
|
|
19
|
+
* `match[0]`.
|
|
20
|
+
*/
|
|
21
|
+
readonly patterns: readonly RegExp[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Lookup table keyed by Wappalyzer provider name.
|
|
25
|
+
*
|
|
26
|
+
* When extending: keep regexes anchored on stable, high-signal substrings
|
|
27
|
+
* (the surrounding API call, not just the bare ID character class). Otherwise
|
|
28
|
+
* the same regex will hit unrelated strings on pages that happen to share the
|
|
29
|
+
* shape (e.g., AWS ARNs containing `GA-...`).
|
|
30
|
+
*/
|
|
31
|
+
export declare const ID_EXTRACTORS: Record<string, IdExtractor>;
|
|
32
|
+
/**
|
|
33
|
+
* Extracts real IDs for `provider` from the page HTML.
|
|
34
|
+
*
|
|
35
|
+
* Returns a de-duplicated, insertion-ordered list of IDs. Returns `[]` for
|
|
36
|
+
* unknown providers (so callers can compose freely).
|
|
37
|
+
* @param provider
|
|
38
|
+
* @param html
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractIds(provider: string, html: string): string[];
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific real-ID extraction rules.
|
|
3
|
+
*
|
|
4
|
+
* `simple-wappalyzer` identifies the *technology* (e.g., "Google Analytics") but
|
|
5
|
+
* does not surface the actual account/measurement ID. We layer real-ID
|
|
6
|
+
* extraction on top: for each detected provider, apply the registered regex
|
|
7
|
+
* over the page HTML and surface what we find.
|
|
8
|
+
*
|
|
9
|
+
* Provider keys must match the names produced by `simple-wappalyzer` exactly;
|
|
10
|
+
* these in turn track `wappalyzer-core@6` (the MIT-licensed fingerprint set).
|
|
11
|
+
*
|
|
12
|
+
* Keep the table **manually maintained**, not generated from Wappalyzer data.
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Lookup table keyed by Wappalyzer provider name.
|
|
17
|
+
*
|
|
18
|
+
* When extending: keep regexes anchored on stable, high-signal substrings
|
|
19
|
+
* (the surrounding API call, not just the bare ID character class). Otherwise
|
|
20
|
+
* the same regex will hit unrelated strings on pages that happen to share the
|
|
21
|
+
* shape (e.g., AWS ARNs containing `GA-...`).
|
|
22
|
+
*/
|
|
23
|
+
export const ID_EXTRACTORS = {
|
|
24
|
+
'Google Analytics': {
|
|
25
|
+
patterns: [
|
|
26
|
+
/gtag\(\s*['"]config['"]\s*,\s*['"](G-[A-Z0-9]{4,20})['"]/g,
|
|
27
|
+
/googletagmanager\.com\/gtag\/js\?id=(G-[A-Z0-9]{4,20})/g,
|
|
28
|
+
/\bga\(\s*['"]create['"]\s*,\s*['"](UA-\d{4,10}-\d{1,4})['"]/g,
|
|
29
|
+
/['"](UA-\d{4,10}-\d{1,4})['"]/g,
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
'Google Tag Manager': {
|
|
33
|
+
patterns: [
|
|
34
|
+
/googletagmanager\.com\/(?:gtm|ns)\.[a-z]+\?id=(GTM-[A-Z0-9]{4,12})/g,
|
|
35
|
+
/['"](GTM-[A-Z0-9]{4,12})['"]/g,
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
'Google Ads': {
|
|
39
|
+
patterns: [/['"](AW-\d{4,12})['"]/g],
|
|
40
|
+
},
|
|
41
|
+
'Facebook Pixel': {
|
|
42
|
+
patterns: [
|
|
43
|
+
/fbq\(\s*['"]init['"]\s*,\s*['"](\d{6,20})['"]/g,
|
|
44
|
+
/connect\.facebook\.net\/[^"']+\/fbevents\.js\D*(\d{6,20})/g,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
Hotjar: {
|
|
48
|
+
patterns: [
|
|
49
|
+
/hjid\s*[:=]\s*(\d{4,10})/g,
|
|
50
|
+
/static\.hotjar\.com\/c\/hotjar-(\d{4,10})\.js/g,
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
'Microsoft Clarity': {
|
|
54
|
+
patterns: [
|
|
55
|
+
/clarity\.ms\/tag\/([a-z0-9]{6,20})/g,
|
|
56
|
+
/clarity\(\s*['"]start['"]\s*,\s*['"]([a-z0-9]{6,20})['"]/gi,
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
Mixpanel: {
|
|
60
|
+
patterns: [/mixpanel\.init\(\s*['"]([a-f0-9]{16,40})['"]/g],
|
|
61
|
+
},
|
|
62
|
+
Segment: {
|
|
63
|
+
patterns: [
|
|
64
|
+
/analytics\.load\(\s*['"]([a-zA-Z0-9]{8,40})['"]/g,
|
|
65
|
+
/cdn\.segment\.com\/analytics\.js\/v1\/([a-zA-Z0-9]{8,40})/g,
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
Amplitude: {
|
|
69
|
+
patterns: [
|
|
70
|
+
/amplitude\.init\(\s*['"]([a-f0-9]{16,40})['"]/g,
|
|
71
|
+
/getInstance\(\)\.init\(\s*['"]([a-f0-9]{16,40})['"]/g,
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
Heap: {
|
|
75
|
+
patterns: [
|
|
76
|
+
/heap\.load\(\s*['"](\d{6,20})['"]/g,
|
|
77
|
+
/heap\.appid\s*=\s*['"](\d{6,20})['"]/g,
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
PostHog: {
|
|
81
|
+
patterns: [/posthog\.init\(\s*['"]([\w-]{16,80})['"]/g],
|
|
82
|
+
},
|
|
83
|
+
Plausible: {
|
|
84
|
+
patterns: [/plausible\.io\/js\/script\.js[?&]domain=([a-zA-Z0-9.,-]+)/g],
|
|
85
|
+
},
|
|
86
|
+
Matomo: {
|
|
87
|
+
patterns: [
|
|
88
|
+
/_paq\.push\(\s*\[\s*['"]setSiteId['"]\s*,\s*['"]?(\d{1,6})['"]?\s*\]/g,
|
|
89
|
+
/matomo\.php\?siteId=(\d{1,6})/g,
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
'Adobe Analytics': {
|
|
93
|
+
patterns: [
|
|
94
|
+
/s_account\s*=\s*['"]([a-z0-9,]{3,50})['"]/gi,
|
|
95
|
+
/s\.account\s*=\s*['"]([a-z0-9,]{3,50})['"]/gi,
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
'Yandex Metrica': {
|
|
99
|
+
patterns: [/ym\(\s*(\d{6,12})\s*,\s*['"]init['"]/g],
|
|
100
|
+
},
|
|
101
|
+
'LinkedIn Insight Tag': {
|
|
102
|
+
patterns: [/_linkedin_partner_id\s*=\s*['"](\d{4,10})['"]/g],
|
|
103
|
+
},
|
|
104
|
+
'Twitter Ads': {
|
|
105
|
+
patterns: [/twq\(\s*['"]config['"]\s*,\s*['"]([a-z0-9]{4,12})['"]/g],
|
|
106
|
+
},
|
|
107
|
+
'TikTok Pixel': {
|
|
108
|
+
patterns: [
|
|
109
|
+
/ttq\.load\(\s*['"]([A-Z0-9]{12,30})['"]/g,
|
|
110
|
+
/tiktok\.com\/i18n\/pixel\/events\.js\?sdkid=([A-Z0-9]{12,30})/g,
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
'Pinterest Tag': {
|
|
114
|
+
patterns: [/pintrk\(\s*['"]load['"]\s*,\s*['"](\d{12,20})['"]/g],
|
|
115
|
+
},
|
|
116
|
+
'Bing Universal Event Tracking': {
|
|
117
|
+
patterns: [
|
|
118
|
+
/setAttribute\(\s*['"]data-tag['"]\s*,\s*['"](\d{6,20})['"]/g,
|
|
119
|
+
/UET\(\{\s*ti:\s*['"](\d{6,20})['"]/g,
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
Optimizely: {
|
|
123
|
+
patterns: [/cdn\.optimizely\.com\/js\/(\d{6,20})\.js/g],
|
|
124
|
+
},
|
|
125
|
+
HubSpot: {
|
|
126
|
+
patterns: [
|
|
127
|
+
/js\.hs-?scripts\.com\/(\d{4,12})\.js/g,
|
|
128
|
+
/js\.hubspot\.com\/web-interactives\/v1\/embeds\/(\d{4,12})/g,
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
Sentry: {
|
|
132
|
+
patterns: [
|
|
133
|
+
/(https:\/\/[a-f0-9]+@[a-zA-Z0-9.-]+\.ingest\.sentry\.io\/\d+)/g,
|
|
134
|
+
/(https:\/\/[a-f0-9]+@[a-zA-Z0-9.-]+\.sentry\.io\/\d+)/g,
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
Intercom: {
|
|
138
|
+
patterns: [
|
|
139
|
+
/intercomSettings\s*=\s*\{[^}]*?app_id:\s*['"]([a-z0-9]{4,10})['"]/g,
|
|
140
|
+
/Intercom\(\s*['"]boot['"]\s*,\s*\{[^}]*?app_id:\s*['"]([a-z0-9]{4,10})['"]/g,
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
Drift: {
|
|
144
|
+
patterns: [/drift\.load\(\s*['"]([a-z0-9]{6,30})['"]/g],
|
|
145
|
+
},
|
|
146
|
+
'Tawk.to': {
|
|
147
|
+
patterns: [/embed\.tawk\.to\/([a-f0-9]{16,40})/g],
|
|
148
|
+
},
|
|
149
|
+
'Zendesk Chat': {
|
|
150
|
+
patterns: [/static\.zdassets\.com\/ekr\/snippet\.js\?key=([a-f0-9-]{16,40})/g],
|
|
151
|
+
},
|
|
152
|
+
Cookiebot: {
|
|
153
|
+
patterns: [/consent\.cookiebot\.com\/uc\.js[^"']*?cbid=([a-f0-9-]{16,40})/g],
|
|
154
|
+
},
|
|
155
|
+
OneTrust: {
|
|
156
|
+
patterns: [/dataDomain['"=]\s*['"]?([a-z0-9-]{16,80})['"]?/gi],
|
|
157
|
+
},
|
|
158
|
+
Stripe: {
|
|
159
|
+
patterns: [/js\.stripe\.com\/v\d+\//g],
|
|
160
|
+
},
|
|
161
|
+
'Google reCAPTCHA': {
|
|
162
|
+
patterns: [/google\.com\/recaptcha\/api\.js[^"']*?(?:render=)?([\w-]{20,60})/g],
|
|
163
|
+
},
|
|
164
|
+
'Facebook for WordPress': {
|
|
165
|
+
patterns: [/fbq\(\s*['"]init['"]\s*,\s*['"](\d{6,20})['"]/g],
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Extracts real IDs for `provider` from the page HTML.
|
|
170
|
+
*
|
|
171
|
+
* Returns a de-duplicated, insertion-ordered list of IDs. Returns `[]` for
|
|
172
|
+
* unknown providers (so callers can compose freely).
|
|
173
|
+
* @param provider
|
|
174
|
+
* @param html
|
|
175
|
+
*/
|
|
176
|
+
export function extractIds(provider, html) {
|
|
177
|
+
const extractor = ID_EXTRACTORS[provider];
|
|
178
|
+
if (!extractor)
|
|
179
|
+
return [];
|
|
180
|
+
const seen = new Set();
|
|
181
|
+
const result = [];
|
|
182
|
+
for (const pattern of extractor.patterns) {
|
|
183
|
+
// Patterns must be `g`-flagged for `matchAll` to work without re-creating.
|
|
184
|
+
const safe = pattern.flags.includes('g')
|
|
185
|
+
? pattern
|
|
186
|
+
: new RegExp(pattern.source, pattern.flags + 'g');
|
|
187
|
+
for (const match of html.matchAll(safe)) {
|
|
188
|
+
const id = match[1] ?? match[0];
|
|
189
|
+
if (id && !seen.has(id)) {
|
|
190
|
+
seen.add(id);
|
|
191
|
+
result.push(id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lookup tables mapping `<meta name>`, `<meta property>`, `<meta http-equiv>`,
|
|
3
|
+
* `<meta itemprop>`, and `<link rel>` to their dot-path in `Meta`.
|
|
4
|
+
*
|
|
5
|
+
* Each key has a single canonical lowercase form. Cross-reference keys
|
|
6
|
+
* (e.g., `format-detection` writes to both `formatDetection.*` and
|
|
7
|
+
* `apple.formatDetectionTelephone`) use `paths` with more than one entry.
|
|
8
|
+
*
|
|
9
|
+
* Values referenced from `frontmatter-keys.md` in `../../frontend-env/`.
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
export type KeyTransform = 'string' | 'number' | 'boolean-yes' | 'boolean-on' | 'boolean-true';
|
|
13
|
+
export type KeyDef = {
|
|
14
|
+
/** One or more dot-paths under `Meta` to write the value into. */
|
|
15
|
+
readonly paths: readonly string[];
|
|
16
|
+
/** When `true`, repeated occurrences accumulate into an array at the path. */
|
|
17
|
+
readonly multi?: boolean;
|
|
18
|
+
/** Value normalization to apply. Defaults to `'string'`. */
|
|
19
|
+
readonly transform?: KeyTransform;
|
|
20
|
+
};
|
|
21
|
+
/** Defines how a `<link rel>` is stored under `Meta.link`. */
|
|
22
|
+
export type LinkRelDef = {
|
|
23
|
+
/** Dot-path under `Meta.link` (e.g., `'canonical'`, `'preload'`). */
|
|
24
|
+
readonly path: string;
|
|
25
|
+
/**
|
|
26
|
+
* `'single'` keeps the first; `'href-only'` stores the href string only;
|
|
27
|
+
* `'array'` accumulates `LinkEntry[]`; `'icon-sized'` accumulates only when
|
|
28
|
+
* `sizes` is set.
|
|
29
|
+
*/
|
|
30
|
+
readonly cardinality: 'single' | 'href-only' | 'array' | 'icon-sized';
|
|
31
|
+
};
|
|
32
|
+
/** `<meta name="X">` → dot-path in `Meta`. */
|
|
33
|
+
export declare const META_NAME_MAP: Record<string, KeyDef>;
|
|
34
|
+
/** `<meta property="X">` → dot-path in `Meta`. */
|
|
35
|
+
export declare const META_PROPERTY_MAP: Record<string, KeyDef>;
|
|
36
|
+
/** `<meta http-equiv="X">` → dot-path in `Meta.httpEquiv`. */
|
|
37
|
+
export declare const HTTP_EQUIV_MAP: Record<string, KeyDef>;
|
|
38
|
+
/** `<meta itemprop="X">` → dot-path in `Meta.itemprop`. */
|
|
39
|
+
export declare const ITEMPROP_MAP: Record<string, KeyDef>;
|
|
40
|
+
/** `<link rel="X">` → dot-path in `Meta.link`. */
|
|
41
|
+
export declare const LINK_REL_MAP: Record<string, LinkRelDef>;
|