Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
343 lines (299 loc) · 8.23 KB
/
Copy pathtypes.ts
File metadata and controls
343 lines (299 loc) · 8.23 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/** What to do next: monitor the next window, or act now. Not a score band. */
export type AnalyticsInsightResponse = "watch" | "action";
export interface AnalyticsSearchConsoleConfig {
siteUrl: string;
}
export interface AnalyticsGa4Config {
propertyId: string;
}
/** GSC / GA4 pull knobs. Running `pend-analytics audit` force-enables sources. */
export interface AnalyticsConfig {
enabled: boolean;
/** Path to service-account JSON; empty/omit → GOOGLE_APPLICATION_CREDENTIALS. */
credentialsPath?: string;
/** PageSpeed / CrUX key; empty/omit → PAGESPEED_API_KEY. */
pagespeedApiKey?: string;
/** Inclusive day count for the primary window (default 28). */
rangeDays: number;
/** YYYY-MM-DD overrides; when both set, rangeDays is ignored. */
startDate?: string;
endDate?: string;
/** Compare against the immediately preceding window of equal length. */
comparePrevious: boolean;
searchConsole?: AnalyticsSearchConsoleConfig;
ga4?: AnalyticsGa4Config;
/**
* Optional Chromium probe: intercept GA collect on a cold load, then abort
* so client GA4 is not inflated. Off unless set, or ANALYTICS_OBSERVE=1.
*/
observeEvents?: boolean;
/** Named rival https origins. Homepage CrUX + PSI. Never your Google property. */
rivals?: string[];
}
export const ANALYTICS_STANDARD = "Pendulum_Analytics_v1" as const;
export type AnalyticsStandard = typeof ANALYTICS_STANDARD;
export interface AnalyticsEngineConfig {
project: string;
standard: AnalyticsStandard;
baseUrl?: string;
analytics: AnalyticsConfig;
}
export interface AnalyticsRange {
start: string;
end: string;
previousStart?: string;
previousEnd?: string;
}
export interface GscMetricRow {
clicks: number;
impressions: number;
ctr: number;
position: number;
}
export interface GscDailyRow extends GscMetricRow {
date: string;
}
export interface GscPageRow extends GscMetricRow {
page: string;
}
export interface GscQueryRow extends GscMetricRow {
query: string;
}
export interface GscAnalyticsBundle {
siteUrl: string;
daily: GscDailyRow[];
topPages: GscPageRow[];
topQueries: GscQueryRow[];
totals: GscMetricRow;
previousTotals?: GscMetricRow;
}
export interface Ga4DailyRow {
date: string;
sessions: number;
totalUsers: number;
engagedSessions: number;
}
export interface Ga4LandingPageRow {
path: string;
sessions: number;
engagementRate: number;
}
export interface Ga4NamedCount {
name: string;
sessions: number;
}
export interface Ga4OrganicDailyRow {
date: string;
sessions: number;
}
export interface Ga4NewReturningDailyRow {
date: string;
newUsers: number;
returningUsers: number;
}
export interface Ga4AnalyticsBundle {
propertyId: string;
daily: Ga4DailyRow[];
landingPages: Ga4LandingPageRow[];
/** Organic Search sessions by day. */
organicDaily: Ga4OrganicDailyRow[];
/** Period totals by default channel group. */
channels: Ga4NamedCount[];
/** Period totals by device category. */
devices: Ga4NamedCount[];
/** New vs returning users by day. */
newReturningDaily: Ga4NewReturningDailyRow[];
totals: { sessions: number; totalUsers: number; engagedSessions: number };
previousTotals?: { sessions: number; totalUsers: number; engagedSessions: number };
}
export interface RemediationCopy {
engineer: string;
client: string;
}
export interface AnalyticsInsight {
id: string;
response: AnalyticsInsightResponse;
title: string;
detail: string;
remediation: RemediationCopy;
}
export interface AnalyticsError {
source: "gsc" | "ga4" | "auth" | "tags" | "observe" | "crux" | "psi" | "rival";
message: string;
/** Origin for psi, crux, and rival rows. Distinguishes the site from named rivals. */
host?: string;
}
export type GoogleTagSnippetKind = "gtm" | "gtag" | "ua" | "other";
export type GoogleTagLocation = "head" | "body" | "unknown";
export type GoogleDestinationFamily =
| "gtm"
| "ga4"
| "ua"
| "ads"
| "floodlight"
| "consent";
export type GoogleTagCollisionCode =
| "multiple-ga4-ids"
| "gtm-plus-standalone-gtag"
| "multiple-gtm"
| "ua-leftover"
| "bound-property-missing"
| "url-drift";
export interface GoogleSetupDestination {
family: GoogleDestinationFamily;
id: string;
}
export interface GoogleSetupSnippet {
kind: GoogleTagSnippetKind;
location: GoogleTagLocation;
text: string;
fingerprint: string;
destinations: GoogleSetupDestination[];
/** Pages this snippet was found on. */
pages: string[];
}
export interface GoogleSetupGtmContainer {
containerId: string;
tagTypeCounts?: Record<string, number>;
destinations?: string[];
parseError?: string;
}
export interface GoogleSetupCollision {
code: GoogleTagCollisionCode;
severity: "action" | "watch" | "info";
detail: string;
urls?: string[];
}
export interface GoogleSetupBundle {
/** URLs fetched for the public tag scan, homepage first. */
urls: string[];
/** Unique snippets. Destinations live on the snippet they were read from. */
snippets: GoogleSetupSnippet[];
gtm?: GoogleSetupGtmContainer[];
collisions: GoogleSetupCollision[];
}
export interface GoogleSetupEventsBundle {
configured: Array<{
name: string;
source: "html" | "gtm";
trigger?: string;
}>;
received: Array<{ name: string; count: number }>;
/** Present when the Chromium observe probe ran (may be empty). */
observed?: Array<{ name: string; count: number }>;
}
export type CruxReason = "not-found" | "empty" | "error";
/** Origin Chrome UX Report field vitals (p75). */
export interface CruxOriginBundle {
origin: string;
/** Set when vitals are missing so the report says why. */
reason?: CruxReason;
/** Google or transport message for not-found and error. */
detail?: string;
collectionStart?: string;
collectionEnd?: string;
lcpMs?: number;
inpMs?: number;
cls?: number;
}
export type PsiStrategy = "mobile" | "desktop";
export type PsiLabMetricId = "fcp" | "lcp" | "tbt" | "cls" | "si";
export interface PsiLabMetric {
id: PsiLabMetricId;
value: number;
displayValue?: string;
score?: number;
}
export type PsiInsightKind = "opportunity" | "diagnostic" | "insight";
export interface PsiInsight {
id: string;
title: string;
kind: PsiInsightKind;
savingsMs?: number;
savingsBytes?: number;
score?: number;
displayValue?: string;
description?: string;
}
export interface PsiPageRow {
url: string;
strategy: PsiStrategy;
score?: number;
opportunities?: Array<{ id: string; title: string; savingsMs?: number }>;
metrics?: PsiLabMetric[];
insights?: PsiInsight[];
lighthouseVersion?: string;
fetchTime?: string;
error?: string;
screenshot?: string;
}
export interface PsiLabBundle {
pages: PsiPageRow[];
}
export interface RivalOriginObservation {
host: string;
crux?: CruxOriginBundle;
psi?: PsiLabBundle;
error?: string;
}
export interface AnalyticsBundle {
range: AnalyticsRange;
gsc?: GscAnalyticsBundle;
ga4?: Ga4AnalyticsBundle;
googleSetup?: GoogleSetupBundle;
events?: GoogleSetupEventsBundle;
crux?: CruxOriginBundle;
psi?: PsiLabBundle;
rivals?: RivalOriginObservation[];
insights: AnalyticsInsight[];
errors?: AnalyticsError[];
}
export interface IssueBurden {
critical: number;
serious: number;
moderate: number;
minor: number;
uniqueRules: number;
}
export interface ManualProgress {
total: number;
completed: number;
percent: number;
}
export type ScoreBand = "Excellent" | "Good" | "Needs work" | "Critical gaps";
/** Unscored envelope kept so consumers that read `score` still parse. */
export interface ScoreSummary {
automatedReadiness: number;
worstPageScore: number;
band: ScoreBand;
burden: IssueBurden;
manual: ManualProgress;
}
export interface AuditTiming {
totalMs: number;
browserLaunchMs: number;
crawlMs: number;
analyzeMs: number;
postProcessMs?: number;
urlCount: number;
navigationCount: number;
pageConcurrency: number;
pages: [];
}
/**
* Analytics --out envelope. `pages` and `findings` stay empty; the payload
* is `analytics`. Score is zeros on purpose - this engine does not rate traffic.
*/
export interface AuditRun {
version: 1;
tool: string;
generatedAt: string;
project: string;
standard: string;
baseUrl?: string;
score: ScoreSummary;
pages: [];
findings: [];
analytics: AnalyticsBundle;
timing?: AuditTiming;
}