fix(stats): unify success rate formula across admin and public metrics

Merged
RI
3mo ago
+94-49

Summary (AI generated)

  • Public /data live update metrics now compute headline success rate from version_usage using install / (install + fail), matching the admin dashboard formula.
  • Fixed getUpdateStatsCF, getUpdate_stats SQL, and getUpdateStatsSB, which previously used get / (install + get) — not a real install success rate.
  • Public dimensional breakdowns (platform/country/version) now use event counts from app_log instead of device-day dedup that produced a separate ~70% number.

Motivation (AI generated)

The marketing /data page and admin dashboard showed different success rates because they used different datasets and formulas. A prior fix aligned public stats with global_stats, but a follow-up PR reintroduced a separate Analytics Engine device-day calculation from app_log. Meanwhile, the cron snapshot stored in global_stats used get/(install+get), which is also semantically wrong for "successful update installations".

Business Impact (AI generated)

Capgo can now publish one consistent, correct install success rate on the marketing page and admin dashboard. This removes misleading lower public numbers and prevents overstating success via the old get-ratio formula.

Test Plan (AI generated)

  • npx vitest run tests/public-live-update-metrics.unit.test.ts tests/public-stats.unit.test.ts tests/cron-email-stats-backtest.unit.test.ts
  • Deploy and compare /private/website_stats/live_updates success_rate with admin success_rate metric for the same 30-day window
  • Verify next global_stats cron run stores updated success_rate values after migration

Generated with AI

Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved update success-rate accuracy by counting completed installs and failures, excluding download events.
    • Updated live metrics to reflect outcomes across platforms, countries, and updater versions more reliably.
    • Preserved existing app health-status thresholds while correcting the underlying calculations.
  • Tests

    • Updated analytics coverage to verify install/failure-based metrics and version-usage data.