From c370785510857f61ce8fecad16e1a03d4179200d Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Wed, 16 Jun 2021 16:22:22 +0200 Subject: [PATCH] Merge pull request #4216 from overleaf/ab-mixpanel-events-cleanup Cleanup analytics subscription events GitOrigin-RevId: b55debe0d76f5e2d84e12de9cced8f69a03b8b95 --- .../Subscription/RecurlyEventHandler.js | 10 ++++-- .../Subscription/SubscriptionHandler.js | 3 -- .../Subscription/RecurlyEventHandlerTests.js | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js index a5780440ab..f21815b051 100644 --- a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js +++ b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js @@ -21,12 +21,18 @@ function sendRecurlyAnalyticsEvent(event, eventData) { _sendSubscriptionReactivatedEvent(eventData) break case 'paid_charge_invoice_notification': - if (eventData.invoice.state === 'paid') { + if ( + eventData.invoice.state === 'paid' && + eventData.invoice.total_in_cents > 0 + ) { _sendInvoicePaidEvent(eventData) } break case 'closed_invoice_notification': - if (eventData.invoice.state === 'collected') { + if ( + eventData.invoice.state === 'collected' && + eventData.invoice.total_in_cents > 0 + ) { _sendInvoicePaidEvent(eventData) } break diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.js b/services/web/app/src/Features/Subscription/SubscriptionHandler.js index 73286fdeca..4d7027a261 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.js @@ -7,7 +7,6 @@ const logger = require('logger-sharelatex') const SubscriptionUpdater = require('./SubscriptionUpdater') const LimitationsManager = require('./LimitationsManager') const EmailHandler = require('../Email/EmailHandler') -const Analytics = require('../Analytics/AnalyticsManager') const PlansLocator = require('./PlansLocator') const SubscriptionHelper = require('./SubscriptionHelper') @@ -220,7 +219,6 @@ const SubscriptionHandler = { ), ONE_HOUR_IN_MS ) - Analytics.recordEvent(user._id, 'subscription-canceled') callback() } ) @@ -260,7 +258,6 @@ const SubscriptionHandler = { } } ) - Analytics.recordEvent(user._id, 'subscription-reactivated') callback() } ) diff --git a/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js b/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js index 5a0d91a7c9..59492c0018 100644 --- a/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js +++ b/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js @@ -250,6 +250,7 @@ describe('RecurlyEventHandler', function () { }, invoice: { state: 'paid', + total_in_cents: 720, }, } ) @@ -260,6 +261,22 @@ describe('RecurlyEventHandler', function () { ) }) + it('with paid_charge_invoice_notification and total_in_cents 0', function () { + this.RecurlyEventHandler.sendRecurlyAnalyticsEvent( + 'paid_charge_invoice_notification', + { + account: { + account_code: this.userId, + }, + invoice: { + state: 'paid', + total_in_cents: 0, + }, + } + ) + sinon.assert.notCalled(this.AnalyticsManager.recordEvent) + }) + it('with closed_invoice_notification', function () { this.RecurlyEventHandler.sendRecurlyAnalyticsEvent( 'closed_invoice_notification', @@ -269,6 +286,7 @@ describe('RecurlyEventHandler', function () { }, invoice: { state: 'collected', + total_in_cents: 720, }, } ) @@ -278,4 +296,20 @@ describe('RecurlyEventHandler', function () { 'subscription-invoice-collected' ) }) + + it('with closed_invoice_notification and total_in_cents 0', function () { + this.RecurlyEventHandler.sendRecurlyAnalyticsEvent( + 'closed_invoice_notification', + { + account: { + account_code: this.userId, + }, + invoice: { + state: 'collected', + total_in_cents: 0, + }, + } + ) + sinon.assert.notCalled(this.AnalyticsManager.recordEvent) + }) })