Uploaded image for project: 'Konflux UI'
  1. Konflux UI
  2. KFLUXUI-1049

Initialize Segment on App Startup

XMLWordPrintable

    • Icon: Story Story
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • None
    • None

      Acceptance Criteria

      • An initAnalytics() function is exported from src/analytics/index.ts.
      • When ANALYTICS_ENABLED is true and a valid write key is present, it loads and initializes the Segment SDK with the configured write key and API URL.
      • When disabled, initialization is skipped entirely — no SDK loaded, no network requests.
      • The initialized Segment analytics instance is accessible to other modules that need it (e.g., via a getAnalytics() getter).
      • Initialization is called in main.tsx alongside initMonitoring(), non-blocking, the app renders even if Segment fails.
      • Errors during initialization are caught, logged, and reported to Sentry if available.
      • Unit tests verify: successful init with valid config, SDK not loaded when disabled, graceful error handling on init failure.

      Notes

      • Use @segment/analytics-next (Analytics.js 2.0) as the SDK.
      • Use dynamic import for code-splitting so the Segment SDK isn't in the main bundle when disabled.
      • In main.tsx, run initMonitoring() and initAnalytics() in parallel with Promise.allSettled().
      • getAnalytics() returns the instance or undefined — callers must handle the undefined case (analytics disabled or not yet initialized).

              rh-ee-mtakac Milan Takac
              sbudhwar-1 Sahil Budhwar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: