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

    Function trackEvent

    • Sends one event to PostHog's capture endpoint, identified by getFingerprintDistinctId and tagged with the current getSessionId. No-ops (before touching session storage) when canSendAnalytics says not to. Text params are truncated to PARAM_VALUE_LIMIT; numeric params pass through as numbers. Never throws.

      Parameters

      • name: string

        Event name (e.g. "$exception").

      • params: Record<string, AnalyticsValue> = {}

        Non-PII event properties.

      Returns Promise<void>

      A promise that resolves once the send settles.

      await trackEvent("extension_installed", { app_version: "1.8.0" });
      
      export async function trackEvent(name: string, params: Record<string, AnalyticsValue> = {}): Promise<void> {
      if (!(await canSendAnalytics())) return;

      const properties: Record<string, AnalyticsValue> = {
      $lib: 'chempal-extension',
      $lib_version: __APP_VERSION__,
      $session_id: await getSessionId(),
      };
      for (const [key, value] of Object.entries(params)) {
      // Only plain string params get the length clamp — structured properties
      // like $exception_list pass through untouched.
      properties[key] = typeof value === 'string' ? value.slice(0, PARAM_VALUE_LIMIT) : value;
      }
      return postCaptureEvent({
      event: name,
      distinct_id: getFingerprintDistinctId(),
      properties,
      });
      }