From db717f446f992b65e07767dfe6c1f5f17ec109cb Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 9 Mar 2023 15:28:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20free=20trials=20not=20vi?= =?UTF-8?q?sible=20in=20paid=20subscriptions=20graph?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Team/issues/2607 When a free trial converts to a paid subscription, and increases the MRR, it just creates a 'updated' paid subscription event. To fix this, we need to count updated events that didn't change plan but do have a positive MRR. As an extension we could also check if the MRR change matches the expected MRR for the corresponsing Stripe plan, but that requires a more complex condition check (because for yearly subscriptions we need to convert to monthly), I don't think that is required here. --- ghost/stats-service/lib/subscriptions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ghost/stats-service/lib/subscriptions.js b/ghost/stats-service/lib/subscriptions.js index 4f3a758cfa..fe3bccd35a 100644 --- a/ghost/stats-service/lib/subscriptions.js +++ b/ghost/stats-service/lib/subscriptions.js @@ -95,6 +95,7 @@ class SubscriptionStatsService { CASE WHEN members_paid_subscription_events.type IN ('created','reactivated','active') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 WHEN members_paid_subscription_events.type='updated' AND price.id = to_price.id THEN 1 + WHEN members_paid_subscription_events.type='updated' AND members_paid_subscription_events.from_plan = members_paid_subscription_events.to_plan AND members_paid_subscription_events.mrr_delta > 0 THEN 1 ELSE 0 END ) as positive_delta`)) @@ -108,6 +109,7 @@ class SubscriptionStatsService { .select(knex.raw(`SUM( CASE WHEN members_paid_subscription_events.type IN ('created','reactivated','active') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 + WHEN members_paid_subscription_events.type='updated' AND members_paid_subscription_events.from_plan = members_paid_subscription_events.to_plan AND members_paid_subscription_events.mrr_delta > 0 THEN 1 ELSE 0 END ) as signups`))