From 347cade55f5f50f68a8d685461983007a559f37e Mon Sep 17 00:00:00 2001 From: roo hutton Date: Thu, 30 Jan 2025 09:59:22 +0000 Subject: [PATCH] Merge pull request #23177 from overleaf/rh-pause-tracking Add tracking for subscription-pause-scheduled event GitOrigin-RevId: 802899e53d22f2be49f2d20adb45a4a47d0f6beb --- .../Subscription/SubscriptionController.js | 14 ++++++++++++++ .../components/dashboard/pause-modal.tsx | 1 + .../Subscription/SubscriptionControllerTests.js | 1 + 3 files changed, 16 insertions(+) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 3c25f4f4fa..694c559f07 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -198,6 +198,20 @@ async function pauseSubscription(req, res, next) { ) try { await SubscriptionHandler.promises.pauseSubscription(user, pauseCycles) + + const { subscription } = + await LimitationsManager.promises.userHasSubscription(user) + + AnalyticsManager.recordEventForUserInBackground( + user._id, + 'subscription-pause-scheduled', + { + pause_length: pauseCycles, + plan_code: subscription?.planCode, + subscriptionId: subscription?.id, + } + ) + return res.sendStatus(200) } catch (err) { if (err instanceof Error) { diff --git a/services/web/frontend/js/features/subscription/components/dashboard/pause-modal.tsx b/services/web/frontend/js/features/subscription/components/dashboard/pause-modal.tsx index 9d690dcb69..b23ea490e8 100644 --- a/services/web/frontend/js/features/subscription/components/dashboard/pause-modal.tsx +++ b/services/web/frontend/js/features/subscription/components/dashboard/pause-modal.tsx @@ -66,6 +66,7 @@ export default function PauseSubscriptionModal() { const newUrl = new URL(location.toString()) newUrl.searchParams.set('flash', 'paused') window.history.replaceState(null, '', newUrl) + location.reload() } catch (err) { debugConsole.error('error pausing subscription', err) diff --git a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js index 1000e4b48f..3db2df9ce8 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js @@ -172,6 +172,7 @@ describe('SubscriptionController', function () { './Errors': SubscriptionErrors, '../Analytics/AnalyticsManager': (this.AnalyticsManager = { recordEventForUser: sinon.stub(), + recordEventForUserInBackground: sinon.stub(), recordEventForSession: sinon.stub(), setUserPropertyForUser: sinon.stub(), }),