ChemPal Documentation - v1.17.0
    Preparing search index...

    Function canSendAnalytics

    • 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.

      Returns Promise<boolean>

      true if a capture request should be sent.

      export async function canSendAnalytics(): Promise<boolean> {
      if (import.meta.env.MODE === 'test') return false;
      if (!analyticsConfig.apiKey) return false;
      return analyticsEnabled();
      }