Merge pull request #4216 from overleaf/ab-mixpanel-events-cleanup

Cleanup analytics subscription events

GitOrigin-RevId: b55debe0d76f5e2d84e12de9cced8f69a03b8b95
This commit is contained in:
Alexandre Bourdin 2021-06-16 16:22:22 +02:00 committed by Copybot
parent 9f1784b4c4
commit c370785510
3 changed files with 42 additions and 5 deletions

View file

@ -21,12 +21,18 @@ function sendRecurlyAnalyticsEvent(event, eventData) {
_sendSubscriptionReactivatedEvent(eventData) _sendSubscriptionReactivatedEvent(eventData)
break break
case 'paid_charge_invoice_notification': case 'paid_charge_invoice_notification':
if (eventData.invoice.state === 'paid') { if (
eventData.invoice.state === 'paid' &&
eventData.invoice.total_in_cents > 0
) {
_sendInvoicePaidEvent(eventData) _sendInvoicePaidEvent(eventData)
} }
break break
case 'closed_invoice_notification': case 'closed_invoice_notification':
if (eventData.invoice.state === 'collected') { if (
eventData.invoice.state === 'collected' &&
eventData.invoice.total_in_cents > 0
) {
_sendInvoicePaidEvent(eventData) _sendInvoicePaidEvent(eventData)
} }
break break

View file

@ -7,7 +7,6 @@ const logger = require('logger-sharelatex')
const SubscriptionUpdater = require('./SubscriptionUpdater') const SubscriptionUpdater = require('./SubscriptionUpdater')
const LimitationsManager = require('./LimitationsManager') const LimitationsManager = require('./LimitationsManager')
const EmailHandler = require('../Email/EmailHandler') const EmailHandler = require('../Email/EmailHandler')
const Analytics = require('../Analytics/AnalyticsManager')
const PlansLocator = require('./PlansLocator') const PlansLocator = require('./PlansLocator')
const SubscriptionHelper = require('./SubscriptionHelper') const SubscriptionHelper = require('./SubscriptionHelper')
@ -220,7 +219,6 @@ const SubscriptionHandler = {
), ),
ONE_HOUR_IN_MS ONE_HOUR_IN_MS
) )
Analytics.recordEvent(user._id, 'subscription-canceled')
callback() callback()
} }
) )
@ -260,7 +258,6 @@ const SubscriptionHandler = {
} }
} }
) )
Analytics.recordEvent(user._id, 'subscription-reactivated')
callback() callback()
} }
) )

View file

@ -250,6 +250,7 @@ describe('RecurlyEventHandler', function () {
}, },
invoice: { invoice: {
state: 'paid', 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 () { it('with closed_invoice_notification', function () {
this.RecurlyEventHandler.sendRecurlyAnalyticsEvent( this.RecurlyEventHandler.sendRecurlyAnalyticsEvent(
'closed_invoice_notification', 'closed_invoice_notification',
@ -269,6 +286,7 @@ describe('RecurlyEventHandler', function () {
}, },
invoice: { invoice: {
state: 'collected', state: 'collected',
total_in_cents: 720,
}, },
} }
) )
@ -278,4 +296,20 @@ describe('RecurlyEventHandler', function () {
'subscription-invoice-collected' '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)
})
}) })