@liiift-studio/sanity-visitor-insights 0.3.0 → 0.3.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/index.js +49 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -76
- package/dist/index.mjs.map +1 -1
- 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/src/studio/Figure.tsx +17 -35
- package/src/studio/panels.tsx +62 -50
package/dist/server.mjs
CHANGED
|
@@ -407,6 +407,12 @@ function sumFirstMetric(report) {
|
|
|
407
407
|
|
|
408
408
|
// src/server/vercel.ts
|
|
409
409
|
var API_BASE = "https://api.vercel.com/v1/query/web-analytics";
|
|
410
|
+
function granularityFor(start, end) {
|
|
411
|
+
const days = Math.round((Date.parse(`${end}T00:00:00Z`) - Date.parse(`${start}T00:00:00Z`)) / 864e5) + 1;
|
|
412
|
+
if (days <= 62) return "day";
|
|
413
|
+
if (days <= 26 * 7) return "week";
|
|
414
|
+
return "month";
|
|
415
|
+
}
|
|
410
416
|
function createVercelClient(projectId, token, teamId) {
|
|
411
417
|
async function query(path, extra) {
|
|
412
418
|
const params = new URLSearchParams({ projectId, ...extra });
|
|
@@ -429,8 +435,11 @@ function createVercelClient(projectId, token, teamId) {
|
|
|
429
435
|
query("visits/aggregate", {
|
|
430
436
|
since: start,
|
|
431
437
|
until: end,
|
|
432
|
-
by:
|
|
438
|
+
by: granularityFor(start, end),
|
|
433
439
|
limit: "100"
|
|
440
|
+
}).catch((e) => {
|
|
441
|
+
console.error("Visitor insights: Vercel series unavailable:", e.message);
|
|
442
|
+
return { data: [] };
|
|
434
443
|
})
|
|
435
444
|
]);
|
|
436
445
|
const byDate = {};
|