Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 48 additions & 122 deletions README.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"db:migrate": "wrangler d1 migrations apply scientfactory-downloads --remote",
"analytics:report": "node scripts/analytics-report.mjs",
"analytics:insights": "node scripts/product-insights.mjs",
"analytics:dashboards": "node scripts/manage-posthog-dashboards.mjs",
"analytics:reconcile": "node scripts/reconcile-analytics-pipeline.mjs",
"identity:link": "node scripts/link-analytics-identity.mjs",
"events:types": "wrangler types workers/events/worker-configuration.d.ts --config workers/events/wrangler.jsonc --env-interface AnalyticsWorkerBindings --include-runtime false",
"events:types:check": "wrangler types workers/events/worker-configuration.d.ts --config workers/events/wrangler.jsonc --env-interface AnalyticsWorkerBindings --include-runtime false --check",
Expand Down
63 changes: 0 additions & 63 deletions scripts/analytics-reconciliation.mjs

This file was deleted.

36 changes: 0 additions & 36 deletions scripts/analytics-reconciliation.test.mjs

This file was deleted.

25 changes: 1 addition & 24 deletions scripts/analytics-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";

export const analyticsReportQuery = `
WITH expected_maintenance(name) AS (
VALUES ('retention'), ('deletion'), ('identity-export'), ('event-export')
VALUES ('retention'), ('deletion')
)
SELECT
'30_day_identity' AS report_section,
Expand Down Expand Up @@ -138,17 +138,6 @@ export const analyticsReportQuery = `

UNION ALL

SELECT
'posthog_delivery' AS report_section,
CASE WHEN posthog_state = 'excluded' OR (source = 'desktop' AND privacy_level = 'diagnostic')
THEN 'first-party-only' ELSE posthog_state END AS item,
COUNT(*) AS event_count,
MAX(received_at) AS latest_event
FROM analytics_events
GROUP BY item

UNION ALL

SELECT '30_day_desktop_diagnostics',
event_name || ':' || COALESCE(json_extract(properties_json, '$.deliveryClass'), 'unknown'),
COUNT(*), MAX(occurred_at)
Expand All @@ -159,18 +148,6 @@ export const analyticsReportQuery = `

UNION ALL

SELECT
'delivery_attention' AS report_section,
source || ':' || CASE WHEN posthog_last_error = 'contract-rejected' THEN 'contract-rejected'
ELSE 'retry-exhausted' END AS item,
COUNT(*) AS event_count,
MAX(received_at) AS latest_event
FROM analytics_events
WHERE posthog_state = 'pending' AND posthog_attempts >= 20
GROUP BY item

UNION ALL

SELECT 'deletion_state', posthog_state, COUNT(*), MAX(requested_at)
FROM analytics_deletion_requests
GROUP BY posthog_state
Expand Down
22 changes: 5 additions & 17 deletions scripts/analytics-report.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ it("keeps remote report chunks within the D1 compound SELECT limit", () => {
}
});

it("reports centrally retained diagnostics separately from PostHog delivery", () => {
it("reports centrally retained diagnostics", () => {
const store = testDatabase();
try {
store.sqlite.exec(`INSERT INTO analytics_events
(event_id, event_name, source, privacy_level, occurred_at, distinct_id, properties_json)
VALUES ('diagnostic', 'app.diagnostics', 'desktop', 'diagnostic', '2026-08-30', 'private-id', '{"deliveryClass":"retrying"}');`);
const rows = store.sqlite.prepare(fixedQuery).all();
expect(rows.find((row) => row.report_section === "posthog_delivery")).toMatchObject({
item: "first-party-only",
event_count: 1,
});
expect(rows.find((row) => row.report_section === "30_day_desktop_diagnostics")).toMatchObject({
event_count: 1,
});
Expand Down Expand Up @@ -61,32 +57,24 @@ it("keeps the aggregate report's 30-day window correct across SQLite and ISO tim
}
});

it("shows blocked erasure, quarantine and missing or stale maintenance without raw errors", () => {
it("shows blocked erasure and missing or stale maintenance without identifiers", () => {
const store = testDatabase();
try {
store.sqlite.exec(`INSERT INTO analytics_events
(event_id, event_name, source, privacy_level, occurred_at, distinct_id, properties_json, posthog_attempts, posthog_last_error)
VALUES ('retry', 'app.health', 'desktop', 'essential', '2026-08-30', 'private-id', '{}', 20, 'private-error-text');
INSERT INTO analytics_deletion_requests (request_id, installation_id, requested_at, posthog_state)
store.sqlite
.exec(`INSERT INTO analytics_deletion_requests (request_id, installation_id, requested_at, posthog_state)
VALUES ('erase', 'private-id', '2026-08-30', 'blocked');
INSERT INTO analytics_maintenance_status VALUES ('retention', '2026-08-31 11:00:00', 'ok');`);
const rows = store.sqlite.prepare(fixedQuery).all();
expect(rows.find((row) => row.report_section === "delivery_attention")).toMatchObject({
item: "desktop:retry-exhausted",
event_count: 1,
});
expect(rows.find((row) => row.report_section === "deletion_state")).toMatchObject({
item: "blocked",
event_count: 1,
});
const maintenance = rows.filter((row) => row.report_section === "maintenance");
expect(maintenance.map((row) => row.item).sort()).toEqual([
"deletion:never-run",
"event-export:never-run",
"identity-export:never-run",
"retention:stale-ok",
]);
expect(JSON.stringify(rows)).not.toMatch(/private-id|private-error-text/);
expect(JSON.stringify(rows)).not.toContain("private-id");
} finally {
store.close();
}
Expand Down
171 changes: 0 additions & 171 deletions scripts/manage-posthog-dashboards.mjs

This file was deleted.

Loading