fix(analytics): harden analytics opt-out and feedback surfaces (#423)

Server stops phoning Sentry home after opt-out (release-health sessions + client reports off); settings saves diff-send only changed keys so a stale tab cannot revert an instance-wide opt-out; disabling analytics hides the feedback UI immediately; optIn resumes PostHog after re-enable; onboarding survey writes time out at 15s; inline tool-feedback prompt arms a shown-cooldown.
This commit is contained in:
SnapOtter
2026-07-04 14:02:28 +08:00
committed by GitHub
parent 6e3a14ec6b
commit 23efce9df0
11 changed files with 233 additions and 33 deletions
+29
View File
@@ -234,4 +234,33 @@ describe("Analytics No-Leak Invariant (baked model)", () => {
).toBeNull();
});
});
describe("runtime opt-out / opt-in toggle", () => {
it("opts in to capturing when analytics initializes enabled (clears a stale persisted opt-out)", async () => {
await mod.initAnalytics(enabledConfig);
const instance = mockPosthogInit.mock.results.at(-1)?.value;
expect(instance.opt_in_capturing).toHaveBeenCalled();
});
it("optOut() stops track() and opts out of capturing", async () => {
await mod.initAnalytics(enabledConfig);
const instance = mockPosthogInit.mock.results.at(-1)?.value;
mockCapture.mockClear();
mod.optOut();
mod.track("tool_opened", { tool_id: "resize" });
expect(mockCapture).not.toHaveBeenCalled();
expect(instance.opt_out_capturing).toHaveBeenCalled();
});
it("optIn() resumes track() and opts back in after an optOut()", async () => {
await mod.initAnalytics(enabledConfig);
const instance = mockPosthogInit.mock.results.at(-1)?.value;
mod.optOut();
mockCapture.mockClear();
mod.optIn();
mod.track("tool_opened", { tool_id: "resize" });
expect(mockCapture).toHaveBeenCalledWith("tool_opened", { tool_id: "resize" });
expect(instance.opt_in_capturing).toHaveBeenCalled();
});
});
});