54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import type { CollectionConfig } from "payload";
|
|
import { canViewAnalytics } from "@/access";
|
|
|
|
/**
|
|
* One row per calendar day, upserted by the cleanup cron
|
|
* (lib/analytics/cleanup.ts) from raw analytics-events BEFORE those raw rows
|
|
* age out. This is what lets aggregated history survive well beyond the raw
|
|
* retention window (default 90 days raw vs. 12 months aggregated - see
|
|
* globals/AnalyticsSettings.ts) without keeping individual events around.
|
|
*
|
|
* Not currently read by the main Analytics dashboard filters (those all
|
|
* stay within raw retention by design - see the implementation plan); this
|
|
* exists so long-term aggregated history isn't silently lost once raw
|
|
* events are purged, and is available for a future longer-range view.
|
|
*/
|
|
export const AnalyticsDailyStats: CollectionConfig = {
|
|
slug: "analytics-daily-stats",
|
|
labels: {
|
|
singular: "Tagesstatistik",
|
|
plural: "Tagesstatistiken",
|
|
},
|
|
admin: {
|
|
group: "Auswertung",
|
|
hidden: true,
|
|
},
|
|
access: {
|
|
create: () => false,
|
|
read: canViewAnalytics,
|
|
update: () => false,
|
|
delete: () => false,
|
|
},
|
|
timestamps: true,
|
|
fields: [
|
|
{
|
|
name: "date",
|
|
type: "date",
|
|
required: true,
|
|
unique: true,
|
|
index: true,
|
|
admin: { date: { pickerAppearance: "dayOnly" } },
|
|
},
|
|
{ name: "sessions", type: "number", required: true, defaultValue: 0 },
|
|
{ name: "pageViews", type: "number", required: true, defaultValue: 0 },
|
|
{ name: "uniqueVisitors", type: "number", required: true, defaultValue: 0 },
|
|
// Each a { [key: string]: number } map, e.g. eventCounts.booking_started.
|
|
{ name: "eventCounts", type: "json" },
|
|
{ name: "deviceCounts", type: "json" },
|
|
{ name: "browserCounts", type: "json" },
|
|
{ name: "topPaths", type: "json" },
|
|
{ name: "entryPaths", type: "json" },
|
|
{ name: "exitPaths", type: "json" },
|
|
],
|
|
};
|