mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user