Excluded gift subscriptions from paid subscription charts#27759
Excluded gift subscriptions from paid subscription charts#27759
Conversation
ref https://linear.app/ghost/issue/BER-3615/ - the "Paid subscriptions" bar chart and "Paid subscription breakdown" pie chart were counting gift redemptions as signups and gift end-of-life events as cancellations, which mixed gift activity into charts that are meant to track paid Stripe activity only - gifts now flow through their own member status (`gift`) and surface in the Paid members KPI tooltip instead, so duplicating them in the per- cadence/per-tier breakdowns double-counted activity and made the bar and pie charts disagree - reverted the gift-aware additions to subscription-stats-service so `/stats/subscriptions` returns paid Stripe deltas and counts only; `gift`→`paid` upgrades still appear via the regular paid subscription event flow once the trial converts and MRR begins
WalkthroughThis PR removes gift-handling functionality from the subscription statistics service. The Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ghost/core/core/server/services/stats/subscription-stats-service.js`:
- Around line 15-16: The reverse-walk seeded from paid-only totals (seeded by
fetchSubscriptionCounts() and iterating subscription deltas from
fetchAllSubscriptionDeltas()) fails to decrement paid counts for same-plan
gift/trial → paid "updated" events with mrr_delta > 0, so the pre-conversion
period still shows the user as paid; update the delta handling to detect
same-plan conversion events (in the code that iterates/normalizes deltas
returned by fetchAllSubscriptionDeltas() / where you apply those deltas
backwards) and treat an "updated" event with mrr_delta > 0 that represents a
conversion from gift/trial to paid as a -1 paid subscriber when walking back
before the conversion timestamp (i.e., subtract one from paid count during
rewind), add logic to distinguish true MRR adjustments from conversion-promoting
updates, and add a regression test that simulates a same-plan gift/trial → paid
conversion to assert pre-conversion paid totals decrement correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7a3f33fb-65ba-42be-9cdc-71f010fada6a
📒 Files selected for processing (3)
apps/stats/test/unit/components/growth/new-subscribers-cadence.test.tsxghost/core/core/server/services/stats/subscription-stats-service.jsghost/core/test/unit/server/services/stats/subscriptions.test.js
💤 Files with no reviewable changes (2)
- apps/stats/test/unit/components/growth/new-subscribers-cadence.test.tsx
- ghost/core/test/unit/server/services/stats/subscriptions.test.js
ref https://linear.app/ghost/issue/BER-3614/ ref #27759 - the "Paid subscription breakdown" pie chart was rendering a Complimentary slice derived from the comped delta, which mixed member-status semantics into a chart meant to track paid Stripe subscription activity only - this also caused the pie chart's total to disagree with the "Paid subscriptions" bar chart (which has always been paid-only); with this change the two charts tie out as the issue requires - comp activity is still surfaced in the Paid members KPI tooltip, so no signal is lost for sites that grant complimentary access - removed the now-pointless `calculateStatusSignups` helper that was generalised to support `gift`+`comped` during the gift work but only ever took `'comped'` after gifts moved to the backend
ref https://linear.app/ghost/issue/BER-3615
ref #27624
ref #27703
gift) and surface in the Paid members KPI tooltip instead, so duplicating them in the per- cadence/per-tier breakdowns double-counted activity and made the bar and pie charts disagree/stats/subscriptionsreturns paid Stripe deltas and counts only;gift→paidupgrades still appear via the regular paid subscription event flow once the trial converts and MRR begins