mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 21:31:36 +02:00
Merge pull request #21935 from overleaf/em-recurly-event-ai-add-on
Add an hasAiAddOn property to Recurly events sent to analytics GitOrigin-RevId: a3cfc706001bab3ef06bfaf64d69533b1bc9840a
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
const SubscriptionEmailHandler = require('./SubscriptionEmailHandler')
|
||||
const { AI_ADD_ON_CODE } = require('./RecurlyEntities')
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
|
||||
const INVOICE_SUBSCRIPTION_LIMIT = 10
|
||||
@@ -49,7 +50,7 @@ async function sendRecurlyAnalyticsEvent(event, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionStartedEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -58,6 +59,7 @@ async function _sendSubscriptionStartedEvent(userId, eventData) {
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
is_trial: isTrial,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -83,7 +85,7 @@ async function _sendSubscriptionStartedEvent(userId, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionUpdatedEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -92,6 +94,7 @@ async function _sendSubscriptionUpdatedEvent(userId, eventData) {
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
is_trial: isTrial,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -113,7 +116,7 @@ async function _sendSubscriptionUpdatedEvent(userId, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionCancelledEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -122,6 +125,7 @@ async function _sendSubscriptionCancelledEvent(userId, eventData) {
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
is_trial: isTrial,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -138,7 +142,7 @@ async function _sendSubscriptionCancelledEvent(userId, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionExpiredEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -147,6 +151,7 @@ async function _sendSubscriptionExpiredEvent(userId, eventData) {
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
is_trial: isTrial,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -168,7 +173,7 @@ async function _sendSubscriptionExpiredEvent(userId, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionRenewedEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -177,6 +182,7 @@ async function _sendSubscriptionRenewedEvent(userId, eventData) {
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
is_trial: isTrial,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -198,7 +204,7 @@ async function _sendSubscriptionRenewedEvent(userId, eventData) {
|
||||
}
|
||||
|
||||
async function _sendSubscriptionReactivatedEvent(userId, eventData) {
|
||||
const { planCode, quantity, state, isTrial, subscriptionId } =
|
||||
const { planCode, quantity, state, isTrial, hasAiAddOn, subscriptionId } =
|
||||
_getSubscriptionData(eventData)
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
userId,
|
||||
@@ -206,6 +212,7 @@ async function _sendSubscriptionReactivatedEvent(userId, eventData) {
|
||||
{
|
||||
plan_code: planCode,
|
||||
quantity,
|
||||
has_ai_add_on: hasAiAddOn,
|
||||
subscriptionId,
|
||||
}
|
||||
)
|
||||
@@ -281,12 +288,17 @@ function _getSubscriptionData(eventData) {
|
||||
eventData.subscription.current_period_started_at &&
|
||||
eventData.subscription.trial_started_at.getTime() ===
|
||||
eventData.subscription.current_period_started_at.getTime()
|
||||
const hasAiAddOn =
|
||||
eventData.subscription.subscription_add_ons?.some(
|
||||
addOn => addOn.add_on_code === AI_ADD_ON_CODE
|
||||
) ?? false
|
||||
return {
|
||||
planCode: eventData.subscription.plan.plan_code,
|
||||
quantity: eventData.subscription.quantity,
|
||||
state: eventData.subscription.state,
|
||||
subscriptionId: eventData.subscription.uuid,
|
||||
isTrial,
|
||||
hasAiAddOn,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
is_trial: true,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -113,6 +114,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 3,
|
||||
is_trial: false,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -145,6 +147,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
is_trial: true,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -182,6 +185,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
is_trial: true,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -213,6 +217,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
is_trial: true,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -249,6 +254,7 @@ describe('RecurlyEventHandler', function () {
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
is_trial: true,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
@@ -266,6 +272,7 @@ describe('RecurlyEventHandler', function () {
|
||||
{
|
||||
plan_code: this.planCode,
|
||||
quantity: 1,
|
||||
has_ai_add_on: false,
|
||||
subscriptionId: this.eventData.subscription.uuid,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user