Add Hosted usage overview and daily web preview event

Merged
JJ
2mo ago
+1466-52

Summary

Add a read-only Hosted usage tab under Administration → System health for the two project-operated installations.

  • Require super-admin authorization and an exact trusted APP_DOMAIN of app.sure.am or demo.sure.am, matched to the request host and original Host header. Hide the tab and return 404 for its endpoint on all other hosts, including *.onrender.com.
  • Show retained trial household records from the last 30 days, their current member-account count, and bounded per-household detail (UUID, local subscription status, trial dates and retained sign-in records).
  • Show the existing cleanup scope's total and up to 100 matching households, with the precise eligibility reason and managed-mode scheduling warning.
  • Show local Stripe-linked subscription counts by every status and the active-household subset.
  • Move Trials expiring in next 7 days from Users administration to Hosted usage.
  • Use the existing design system, lazy-frame pattern and localized strings. Group/bound queries, memoize the report, and prevent Active Record writes while building it.

This change adds no cleanup controls, email, Stripe requests, exports/imports, migrations, or customer-facing copy changes.

Daily web preview adoption

Also capture web_app_opened_daily once per authenticated account/browser per browser-local calendar day, with the Boolean preview_features_enabled. Normal browser tabs and installed PWAs both qualify.

  • Remember the state at the first visible opening, including when the SDK becomes ready later. A same-day preference toggle does not send another event or rewrite that day's state.
  • Deduplicate across Turbo navigation, reloads and foreground returns; separate local markers prevent one account suppressing another. Web Locks serialize concurrent tabs where supported.
  • Reuse only the installation's configured normal PostHog client, existing environment gate and capture opt-out. The SDK retains its existing sure_version and metadata.
  • Keep the user ID in a local marker only, with the tracker element excluded from capture/replay. No new identity or financial properties are sent.
  • Skip logged-out pages, hidden documents and cached Turbo previews. Blocked storage omits the event; cleared storage, other devices/browsers and older browsers without Web Locks limit the daily count. SDK acceptance does not guarantee ingestion.
  • Leave the separate shared self-hosted feedback project unchanged. There are no mobile API, Rails Session or background-sync hooks.

Full event contract and counting limits

What the metrics mean

  • The trial cohort uses retained subscription created_at and a non-null trial end date, including converted trials. Imported rows can reflect import time rather than the real trial start.
  • Member accounts are not verified unique people. Retained sessions belong to enabled users; signing out or revoking sessions deletes rows. Session creation is not last-seen activity, visits, or currently-online usage. Shared-demo resets remove history.
  • Cleanup eligibility uses the application's existing scope: paused/trialing subscriptions whose trial ended more than 14 days ago, or households with no subscription older than 45 + 14 days. A recent login does not change that scope. Matching it does not confirm deletion; 90 days is archive retention.
  • Supporter totals require Stripe-shaped local customer and subscription IDs and exclude the synthetic demo sentinel. Local status is not verification of money received or first-payment dates. Supporter, expiring-trial and cleanup totals are current totals, not 30-day acquisition metrics.
  • Summary counts include the complete matching scopes; trial and cleanup tables are capped independently at 100 rows.

Migration-inventory limits

This is a usage overview, not a complete migration inventory. It does not enumerate supporter identities or customer/subscription mappings, audit duplicate/missing mappings, count financial accounts/transactions/imports/chats, inspect authentication dependencies or foreign keys, or decide which records to retain. The UI identifies households by UUID. It has not been run against AWS/production, and compatibility with the currently deployed AWS revision remains unverified.

The HostedUsage reporting object is independent of the UI and can be loaded by Rails runner in a compatible checkout; that does not add the missing inventory checks.

Validation for the daily-event update

The isolated test runtime was restored. All required local checks passed against tree b31be724d65cfe5738a5432ab5ad8b478831904f, published as 7e1e43f410abfca0a0016804b436e98e588fda46 on top of 6f374ef57ee5a7af317fcef5ef88274f04645cc4.

  • Full Rails suite, sequential: 10,528 runs / 44,752 assertions / 0 failures / 0 errors / 33 skips
  • Full system suite: 213 runs / 1,072 assertions / 0 failures / 0 errors / 0 skips
  • Focused daily-event Rails/browser checks: 15 runs / 69 assertions / 0 failures / 0 errors / 0 skips
  • All JavaScript tests: 143 passed, including 9 daily-event tests
  • Ruby lint: passed
  • ERB lint: 756 files, passed
  • Biome: 136 files, passed
  • Brakeman: 0 warnings / 0 errors, with 9 existing ignored warnings
  • Diff whitespace and JavaScript syntax: passed

Offline tests cover local midnight, account switching, same-day preference changes, Turbo navigation, reloads, visibility/cache boundaries, delayed SDK readiness/locks, capture rejection, opt-out and blocked storage. No live PostHog events were submitted. Fresh desktop/mobile screenshots were inspected using synthetic fixtures and are provided separately for comment attachments; no image files are committed.

Current-head GitHub CI is running; local passes do not imply its completion.

Earlier Hosted usage-only validation

Historical local results, completed before the isolated test runtime was lost. These are not a new run at publication time.

The final tested tree was 2e30f742f0f7cd9f4816234ccdfe42d4776e04a0, based on ec4282e0eba808e443b6c15a11d567c1c4c4f3fb. The original published commit 2b7ff292102458504a217282a9f210dcba824344 has that exact tree; it was reverified before publication.

  • Full Rails suite, sequential: 10,475 runs / 44,507 assertions / 0 failures / 0 errors / 33 skips
  • Full system suite: 189 runs / 961 assertions / 0 failures / 0 errors / 0 skips
  • Focused model/controller/Users tests: 61 runs / 624 assertions / 0 failures / 0 errors / 0 skips
  • Focused Hosted usage system tests: 3 runs / 18 assertions / 0 failures / 0 errors / 0 skips
  • Ruby lint: passed
  • ERB lint: 755 files, passed
  • Biome: 132 files, passed
  • Brakeman: 0 warnings / 0 errors, with 9 existing ignored warnings
  • Diff whitespace, Ruby syntax and YAML parsing: passed
  • Screenshots inspected with synthetic fixtures; mobile document overflow assertion passed

Tests cover authorization, exact-domain/forwarded-host rejection, time-window boundaries, converted trials, retained/deleted/disabled-user sessions, all local subscription statuses, cleanup boundaries, query limits and absence of writes/provider calls.

After initial draft publication, the branch was rebased externally onto efe34c6ffedb42a7acef7febb30c1285794eeea2 and marked ready for review. Follow-up commit 6f374ef57ee5a7af317fcef5ef88274f04645cc4 removes only the three review screenshots from the source tree; the 16 application, locale and test files are unchanged from the original tested implementation. Screenshots will be attached in PR comments by the author. The rebased tree has not been tested locally. That earlier head passed GitHub CI (10,523 unit/integration tests and 209 system tests); the local results in this section remain specific to the original tree.

Summary by CodeRabbit

  • New Features
    • Added a hosted-usage report to System Health on supported hosted sites, with summaries of trial households, cleanup eligibility, and supporter statuses.
    • The report loads on demand and includes trial household and session details, empty states, and guidance about the displayed data. It is available in English, German, French, and Portuguese, and displays retained data without triggering cleanup.
  • Changes
    • Removed the seven-day expiring-trial summary card from the admin Users page.