Whether an event should actually leave the device right now: an API key is
configured in config.json (analytics), this isn't a Vitest run
(MODE === "test", independent of whether the test mocked this module —
a safety net against real events leaking from a run that skips the usual
test setup), and the user hasn't opted out. Shared by every capture path so
trackEvent can skip getSessionId's storage write entirely when
the answer is no (an opted-out user shouldn't get session-id writes just
because something called trackEvent), and postCaptureEvent
re-checks it as the final gate right before the fetch. The e2e suite is
deliberately not covered here: it intercepts and aborts capture requests
at the page level (see e2e/search-query.e2e.test.ts) and asserts on them
actually firing.
exportasyncfunctioncanSendAnalytics():Promise<boolean> { if (import.meta.env.MODE==='test') returnfalse; if (!analyticsConfig.apiKey) returnfalse; returnanalyticsEnabled(); }
Whether an event should actually leave the device right now: an API key is configured in
config.json(analytics), this isn't a Vitest run (MODE === "test", independent of whether the test mocked this module — a safety net against real events leaking from a run that skips the usual test setup), and the user hasn't opted out. Shared by every capture path sotrackEventcan skipgetSessionId's storage write entirely when the answer is no (an opted-out user shouldn't get session-id writes just because something calledtrackEvent), andpostCaptureEventre-checks it as the final gate right before the fetch. The e2e suite is deliberately not covered here: it intercepts and aborts capture requests at the page level (seee2e/search-query.e2e.test.ts) and asserts on them actually firing.