@liiift-studio/sanity-visitor-insights 0.3.0 → 0.3.1
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.js +10 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +10 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/core.test.ts +17 -0
- package/src/server/vercel.ts +23 -1
package/dist/server.js
CHANGED
|
@@ -468,6 +468,12 @@ function sumFirstMetric(report) {
|
|
|
468
468
|
|
|
469
469
|
// src/server/vercel.ts
|
|
470
470
|
var API_BASE = "https://api.vercel.com/v1/query/web-analytics";
|
|
471
|
+
function granularityFor(start, end) {
|
|
472
|
+
const days = Math.round((Date.parse(`${end}T00:00:00Z`) - Date.parse(`${start}T00:00:00Z`)) / 864e5) + 1;
|
|
473
|
+
if (days <= 62) return "day";
|
|
474
|
+
if (days <= 26 * 7) return "week";
|
|
475
|
+
return "month";
|
|
476
|
+
}
|
|
471
477
|
function createVercelClient(projectId, token, teamId) {
|
|
472
478
|
async function query(path, extra) {
|
|
473
479
|
const params = new URLSearchParams({ projectId, ...extra });
|
|
@@ -490,8 +496,11 @@ function createVercelClient(projectId, token, teamId) {
|
|
|
490
496
|
query("visits/aggregate", {
|
|
491
497
|
since: start,
|
|
492
498
|
until: end,
|
|
493
|
-
by:
|
|
499
|
+
by: granularityFor(start, end),
|
|
494
500
|
limit: "100"
|
|
501
|
+
}).catch((e) => {
|
|
502
|
+
console.error("Visitor insights: Vercel series unavailable:", e.message);
|
|
503
|
+
return { data: [] };
|
|
495
504
|
})
|
|
496
505
|
]);
|
|
497
506
|
const byDate = {};
|