@liiift-studio/sanity-visitor-insights 0.2.1 → 0.2.2
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/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +32 -22
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +32 -22
- package/dist/server.mjs.map +1 -1
- package/dist/testing.d.mts +9 -3
- package/dist/testing.d.ts +9 -3
- package/dist/testing.js +4 -2
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +4 -2
- package/dist/testing.mjs.map +1 -1
- package/dist/{vercel-BpDH6Vva.d.mts → vercel-BMEO-Jcw.d.mts} +11 -7
- package/dist/{vercel-BpDH6Vva.d.ts → vercel-BMEO-Jcw.d.ts} +11 -7
- package/package.json +1 -1
- package/src/server/vercel.ts +59 -33
- package/src/testing/fakes.ts +11 -3
package/dist/server.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as SiteAnalyticsConfig, D as DiagnosticReport } from './ranges-DSFapooC.mjs';
|
|
2
2
|
export { A as AcquisitionData, m as CheckStatus, n as ConfigProblem, C as Coverage, d as DateRange, q as DiagnosticCheck, E as EventCutover, s as ExitPage, G as GA4_PROCESSING_LAG_DAYS, t as Ga4Config, J as JourneyData, w as JourneyStep, c as MeasurementHealthData, M as MetricValue, O as OrdersConfig, P as PREEXISTING, e as REPORT_NAMES, b as RangeKey, R as ReportEnvelope, f as ReportError, a as ReportName, g as SourceName, x as SourceRow, h as SourceStatus, T as TypefaceInterestData, y as TypefaceInterestRow, U as UnavailableReason, V as VercelConfig, z as applyCoverage, B as assertValidSiteConfig, i as coverageForRange, F as coverageNotices, H as daysBetween, I as formatInTimeZone, j as isReportName, K as isValidTimeZone, o as ok, p as partial, k as previousRange, L as provisionalDates, N as provisionalNotice, r as resolveRange, Q as shiftDays, u as unavailable, v as validateSiteConfig, l as valueOrNull } from './ranges-DSFapooC.mjs';
|
|
3
|
-
import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-
|
|
4
|
-
export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-
|
|
3
|
+
import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-BMEO-Jcw.mjs';
|
|
4
|
+
export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-BMEO-Jcw.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Request authentication and CORS for the report handler.
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as SiteAnalyticsConfig, D as DiagnosticReport } from './ranges-DSFapooC.js';
|
|
2
2
|
export { A as AcquisitionData, m as CheckStatus, n as ConfigProblem, C as Coverage, d as DateRange, q as DiagnosticCheck, E as EventCutover, s as ExitPage, G as GA4_PROCESSING_LAG_DAYS, t as Ga4Config, J as JourneyData, w as JourneyStep, c as MeasurementHealthData, M as MetricValue, O as OrdersConfig, P as PREEXISTING, e as REPORT_NAMES, b as RangeKey, R as ReportEnvelope, f as ReportError, a as ReportName, g as SourceName, x as SourceRow, h as SourceStatus, T as TypefaceInterestData, y as TypefaceInterestRow, U as UnavailableReason, V as VercelConfig, z as applyCoverage, B as assertValidSiteConfig, i as coverageForRange, F as coverageNotices, H as daysBetween, I as formatInTimeZone, j as isReportName, K as isValidTimeZone, o as ok, p as partial, k as previousRange, L as provisionalDates, N as provisionalNotice, r as resolveRange, Q as shiftDays, u as unavailable, v as validateSiteConfig, l as valueOrNull } from './ranges-DSFapooC.js';
|
|
3
|
-
import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-
|
|
4
|
-
export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-
|
|
3
|
+
import { S as SanityQueryClient, G as Ga4Client, V as VercelClient } from './vercel-BMEO-Jcw.js';
|
|
4
|
+
export { a as Ga4Report, b as Ga4ReportRequest, c as ServiceAccountKey, d as VercelPageviews, e as createGa4Client, f as createVercelClient, p as parseServiceAccountKey } from './vercel-BMEO-Jcw.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Request authentication and CORS for the report handler.
|
package/dist/server.js
CHANGED
|
@@ -427,33 +427,43 @@ function sumFirstMetric(report) {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
// src/server/vercel.ts
|
|
430
|
-
var API_BASE = "https://api.vercel.com";
|
|
430
|
+
var API_BASE = "https://api.vercel.com/v1/query/web-analytics";
|
|
431
431
|
function createVercelClient(projectId, token, teamId) {
|
|
432
|
+
async function query(path, extra) {
|
|
433
|
+
const params = new URLSearchParams({ projectId, ...extra });
|
|
434
|
+
if (teamId) params.set("teamId", teamId);
|
|
435
|
+
const response = await fetch(`${API_BASE}/${path}?${params.toString()}`, {
|
|
436
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
437
|
+
});
|
|
438
|
+
if (!response.ok) {
|
|
439
|
+
throw new Error(`Vercel Web Analytics ${path} failed with ${response.status}`);
|
|
440
|
+
}
|
|
441
|
+
return await response.json();
|
|
442
|
+
}
|
|
432
443
|
return {
|
|
433
444
|
async pageviews(start, end) {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const body = await response.json();
|
|
445
|
+
const [totals, series] = await Promise.all([
|
|
446
|
+
query("visits/count", {
|
|
447
|
+
since: start,
|
|
448
|
+
until: end
|
|
449
|
+
}),
|
|
450
|
+
query("visits/aggregate", {
|
|
451
|
+
since: start,
|
|
452
|
+
until: end,
|
|
453
|
+
by: "day",
|
|
454
|
+
limit: "100"
|
|
455
|
+
})
|
|
456
|
+
]);
|
|
447
457
|
const byDate = {};
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const date = point.key.slice(0, 10);
|
|
452
|
-
const count = typeof point.total === "number" ? point.total : 0;
|
|
453
|
-
byDate[date] = (byDate[date] ?? 0) + count;
|
|
454
|
-
total += count;
|
|
458
|
+
for (const row of series.data ?? []) {
|
|
459
|
+
if (!row.timestamp) continue;
|
|
460
|
+
byDate[row.timestamp.slice(0, 10)] = row.pageviews ?? 0;
|
|
455
461
|
}
|
|
456
|
-
return {
|
|
462
|
+
return {
|
|
463
|
+
byDate,
|
|
464
|
+
total: totals.data?.pageviews ?? 0,
|
|
465
|
+
visitors: totals.data?.visitors ?? 0
|
|
466
|
+
};
|
|
457
467
|
}
|
|
458
468
|
};
|
|
459
469
|
}
|