datadog-ux-utils Documentation - v1.0.0
    Preparing search index...

    Function trackNetwork

    • Start tracking network conditions. Safe to call multiple times; returns an uninstaller that removes listeners.

      • Adds/updates Datadog global context on changes (optional).
      • Emits a sampled Datadog action "network_change" on meaningful changes (optional).
      • Listens to navigator.connection (when available) and the online/offline window events.

      Parameters

      Returns () => void

      import { trackNetwork, isConstrainedNetwork } from "@milliman/dd-ux-utils/env/network";

      const stop = trackNetwork({
      reportChanges: true,
      changeSampleRate: 20,
      constrained: { maxDownlinkMbps: 1, effectiveTypes: ["2g", "slow-2g", "3g"] },
      });

      // Later, e.g., to adjust image quality:
      if (isConstrainedNetwork()) loadLowResImages();

      // On teardown:
      stop();