mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
implement pageviews, events, and channels queries
This commit is contained in:
parent
c1cad16cb9
commit
0a0c1f27c6
24 changed files with 521 additions and 86 deletions
|
|
@ -4,9 +4,9 @@ import { getQueryFilters, parseRequest } from '@/lib/request';
|
|||
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
||||
import {
|
||||
getChannelMetrics,
|
||||
getEventMetrics,
|
||||
getPageviewMetrics,
|
||||
getChannelExpandedMetrics,
|
||||
getEventExpandedMetrics,
|
||||
getPageviewExpandedMetrics,
|
||||
getSessionExpandedMetrics,
|
||||
} from '@/queries';
|
||||
import { z } from 'zod';
|
||||
|
|
@ -46,22 +46,6 @@ export async function GET(
|
|||
if (SESSION_COLUMNS.includes(type)) {
|
||||
const data = await getSessionExpandedMetrics(websiteId, { type, limit, offset }, filters);
|
||||
|
||||
// if (type === 'language') {
|
||||
// const combined = {};
|
||||
|
||||
// for (const { x, y } of data) {
|
||||
// const key = String(x).toLowerCase().split('-')[0];
|
||||
|
||||
// if (combined[key] === undefined) {
|
||||
// combined[key] = { x: key, y };
|
||||
// } else {
|
||||
// combined[key].y += y;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return json(Object.values(combined));
|
||||
// }
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
||||
|
|
@ -69,16 +53,16 @@ export async function GET(
|
|||
let data;
|
||||
|
||||
if (type === 'event') {
|
||||
data = await getEventMetrics(websiteId, { type, limit, offset }, filters);
|
||||
data = await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters);
|
||||
} else {
|
||||
data = await getPageviewMetrics(websiteId, { type, limit, offset }, filters);
|
||||
data = await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters);
|
||||
}
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
||||
if (type === 'channel') {
|
||||
const data = await getChannelMetrics(websiteId, filters);
|
||||
const data = await getChannelExpandedMetrics(websiteId, { limit, offset }, filters);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,22 +46,6 @@ export async function GET(
|
|||
if (SESSION_COLUMNS.includes(type)) {
|
||||
const data = await getSessionMetrics(websiteId, { type, limit, offset }, filters);
|
||||
|
||||
if (type === 'language') {
|
||||
const combined = {};
|
||||
|
||||
for (const { x, y } of data) {
|
||||
const key = String(x).toLowerCase().split('-')[0];
|
||||
|
||||
if (combined[key] === undefined) {
|
||||
combined[key] = { x: key, y };
|
||||
} else {
|
||||
combined[key].y += y;
|
||||
}
|
||||
}
|
||||
|
||||
return json(Object.values(combined));
|
||||
}
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue