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

    Function trackInstallOrUpgrade

    • Reports a fresh install as extension_installed or a version change as extension_upgraded, the latter carrying both the old and new version. Driven by the service worker's chrome.runtime.onInstalled listener.

      Only INSTALL and UPDATE are reported — CHROME_UPDATE and SHARED_MODULE_UPDATE mean the browser changed, not ChemPal. An UPDATE whose previousVersion matches the running version is a reload of an unpacked extension rather than a real upgrade, and is reported as nothing.

      Also a no-op under the e2e suite's build (__IS_E2E_BUILD__). Every e2e run loads the extension into a fresh Chrome profile, so onInstalled fires for real with reason install — unlike trackEvent's other callers, this one runs in the background service worker, whose requests the e2e suite's page-level route interception can't see or abort, so it would otherwise reach production PostHog.

      Parameters

      • reason: "update" | "install" | "chrome_update" | "shared_module_update"

        The reason from chrome.runtime.onInstalled.

      • OptionalpreviousVersion: string

        Version being upgraded from; Chrome supplies this only on an update.

      Returns Promise<void>

      A promise that resolves once the send settles.

      // sends `extension_upgraded` with { app_version: "1.9.0", previous_version: "1.8.0" }
      await trackInstallOrUpgrade(chrome.runtime.OnInstalledReason.UPDATE, "1.8.0");
      export async function trackInstallOrUpgrade(
      reason: `${chrome.runtime.OnInstalledReason}`,
      previousVersion?: string,
      ): Promise<void> {
      if (__IS_E2E_BUILD__) return;
      const { INSTALL, UPDATE } = chrome.runtime.OnInstalledReason;
      if (reason !== INSTALL && reason !== UPDATE) return;
      // Reloading an unpacked extension fires onInstalled with reason "update" and
      // previousVersion equal to the version already running. Reporting that would count
      // every dev reload as an upgrade.
      if (reason === UPDATE && previousVersion === __APP_VERSION__) return;
      const params: Record<string, string | number> = { app_version: __APP_VERSION__ };
      if (previousVersion) params.previous_version = previousVersion;
      return trackEvent(reason === INSTALL ? 'extension_installed' : 'extension_upgraded', params);
      }