* feat(analytics): migrate from Umami to PostHog server-side analytics Replace @umami/node with posthog-node for all server-side telemetry. Add singleton PostHog client, feature tracking POC, DAU heartbeat, and tRPC analytics router. Cron job is now locked (no manual trigger, no custom interval). Update consent copy to explain what we collect and why. * style: auto-fix lint and format * refactor(analytics): simplify + add client-side posthog-js init - Inline constants.ts and track.ts into client.ts (single source) - Remove dead exports (shutdownPostHogAsync, getPostHogClient) - Flatten all DB queries into one Promise.all (no waterfall) - Derive integration/widget totals from group-by (drop redundant counts) - Add posthog-js with dynamic import, gated on enableGeneral - Move Analytics component to body, pass consent from server settings * style: auto-fix lint and format * feat(cron): add hidden flag to cron jobs, hide analytics from task panel The analytics job runs silently in the background — users don't need to see or interact with it. Hidden jobs are filtered out of getAllAsync so they never appear in the management UI. * refactor(analytics): simplify to single toggle, always collect all data Remove granular enableWidgetData/enableIntegrationData/enableUserData toggles. Analytics is now a single on/off switch. When enabled, all anonymous usage data is collected in one flat Promise.all call. Side effect: existing users with enableGeneral=true who had granular flags off will now send all data. This is by design — the granular controls added complexity without meaningful privacy benefit since the data is already anonymous counts. * style: auto-fix lint and format
93 lines
2.5 KiB
TypeScript
93 lines
2.5 KiB
TypeScript
import SuperJSON from "superjson";
|
|
import { describe, expect, test, vi } from "vitest";
|
|
|
|
import type { Session } from "@homarr/auth";
|
|
import { createId } from "@homarr/common";
|
|
import { serverSettings } from "@homarr/db/schema";
|
|
import { createDb } from "@homarr/db/test";
|
|
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
|
|
|
|
import { serverSettingsRouter } from "../serverSettings";
|
|
|
|
// Mock the auth module to return an empty session
|
|
vi.mock("@homarr/auth", () => ({ auth: () => ({}) as Session }));
|
|
|
|
const defaultSession = {
|
|
user: {
|
|
id: createId(),
|
|
permissions: ["admin"],
|
|
colorScheme: "light",
|
|
},
|
|
expires: new Date().toISOString(),
|
|
} satisfies Session;
|
|
|
|
describe("getAll server settings", () => {
|
|
test("getAll should throw error when unauthorized", async () => {
|
|
const db = createDb();
|
|
const caller = serverSettingsRouter.createCaller({
|
|
db,
|
|
deviceType: undefined,
|
|
session: null,
|
|
});
|
|
|
|
await db.insert(serverSettings).values([
|
|
{
|
|
settingKey: defaultServerSettingsKeys[0],
|
|
value: SuperJSON.stringify(defaultServerSettings.analytics),
|
|
},
|
|
]);
|
|
|
|
const actAsync = async () => await caller.getAll();
|
|
|
|
await expect(actAsync()).rejects.toThrow();
|
|
});
|
|
test("getAll should return default server settings when nothing in database", async () => {
|
|
const db = createDb();
|
|
const caller = serverSettingsRouter.createCaller({
|
|
db,
|
|
deviceType: undefined,
|
|
session: defaultSession,
|
|
});
|
|
|
|
const result = await caller.getAll();
|
|
|
|
expect(result).toStrictEqual(defaultServerSettings);
|
|
});
|
|
});
|
|
|
|
describe("saveSettings", () => {
|
|
test("saveSettings should update settings and return true when it updated only one", async () => {
|
|
const db = createDb();
|
|
const caller = serverSettingsRouter.createCaller({
|
|
db,
|
|
deviceType: undefined,
|
|
session: defaultSession,
|
|
});
|
|
|
|
await db.insert(serverSettings).values([
|
|
{
|
|
settingKey: defaultServerSettingsKeys[0],
|
|
value: SuperJSON.stringify(defaultServerSettings.analytics),
|
|
},
|
|
]);
|
|
|
|
await caller.saveSettings({
|
|
settingsKey: "analytics",
|
|
value: {
|
|
enableGeneral: true,
|
|
},
|
|
});
|
|
|
|
const dbSettings = await db.select().from(serverSettings);
|
|
expect(dbSettings).toStrictEqual([
|
|
{
|
|
settingKey: "analytics",
|
|
value: SuperJSON.stringify({
|
|
enableGeneral: true,
|
|
instanceId: null,
|
|
}),
|
|
},
|
|
]);
|
|
});
|
|
});
|