feat: insights

* fix: migration for newly created self-hosting instances

* fix: build script

* wip

* wip

* wip

* fix: tailwind css
This commit is contained in:
Carl-Gerhard Lindesvärd
2025-12-19 09:37:15 +01:00
committed by GitHub
parent 1e4f02fb5e
commit 5f38560373
48 changed files with 4072 additions and 25 deletions

View File

@@ -1,2 +1,3 @@
export * from './src/index';
export * from './src/types.validation';
export * from './src/types.insights';

View File

@@ -553,3 +553,5 @@ export const zCreateImport = z.object({
});
export type ICreateImport = z.infer<typeof zCreateImport>;
export * from './types.insights';

View File

@@ -0,0 +1,43 @@
export type InsightMetricKey = 'sessions' | 'pageviews' | 'share';
export type InsightMetricUnit = 'count' | 'ratio';
export interface InsightMetricEntry {
current: number;
compare: number;
delta: number;
changePct: number | null;
direction: 'up' | 'down' | 'flat';
unit: InsightMetricUnit;
}
export interface InsightDimension {
key: string;
value: string;
displayName?: string;
}
export interface InsightExtra {
[key: string]: unknown;
currentShare?: number;
compareShare?: number;
shareShiftPp?: number;
isNew?: boolean;
isGone?: boolean;
}
/**
* Shared payload shape for insights cards. This is embedded in DB rows and
* shipped to the frontend, so it must remain backwards compatible.
*/
export interface InsightPayload {
kind?: 'insight_v1';
dimensions: InsightDimension[];
primaryMetric: InsightMetricKey;
metrics: Partial<Record<InsightMetricKey, InsightMetricEntry>>;
/**
* Module-specific extra data.
*/
extra?: Record<string, unknown>;
}