Просмотр исходного кода

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

Cleanup analytics subscription events

GitOrigin-RevId: b55debe0d76f5e2d84e12de9cced8f69a03b8b95
Alexandre Bourdin 5 лет назад
Родитель
Сommit
c370785510

+ 8 - 2
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

+ 0 - 3
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()
             }
           )

+ 34 - 0
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)
+  })
 })