Merge pull request #32376 from overleaf/rh-cio-migrate-identifiers

Replace analytics id with user id as main identifier in customer.io

GitOrigin-RevId: 780671a51b652c73a940bc152d8fd6916dd611ce
This commit is contained in:
roo hutton
2026-04-01 10:22:35 +01:00
committed by Copybot
parent 972c6e4710
commit 9197be0ec7
4 changed files with 35 additions and 40 deletions
@@ -457,7 +457,6 @@ async function processMigration(input, commit) {
recurlySubscription,
stripeClient,
stripeCustomer,
analyticsId,
mongoUser?.email
)
} catch (err) {
@@ -685,7 +684,6 @@ async function performCutover(
recurlySubscription,
stripeClient,
stripeCustomer,
analyticsId,
mongoUserEmail
) {
const adminUserId = mongoSubscription.admin_id.toString()
@@ -785,27 +783,25 @@ async function performCutover(
}
// Step 6. Send data to customer.io
if (analyticsId) {
try {
const migrationDate = new Date().toISOString().slice(0, 10)
const needsToUpdateTaxInfo =
(stripeCustomer.metadata?.taxInfoPending || '').length > 0
try {
const migrationDate = new Date().toISOString().slice(0, 10)
const needsToUpdateTaxInfo =
(stripeCustomer.metadata?.taxInfoPending || '').length > 0
// TODO: request Recurly account and billingInfo to verify if tax info in Stripe is up to date
// TODO: request Recurly account and billingInfo to verify if tax info in Stripe is up to date
CustomerIoHandler.updateUserAttributes(analyticsId, {
email: mongoUserEmail || stripeCustomer.email,
stripe_migration: {
migration_date: migrationDate,
needs_to_update_tax_id: needsToUpdateTaxInfo,
},
})
} catch (err) {
throw new ReportError(
'migrated-customerio-upload-failed',
`Successfully migrated to Stripe but failed to upload user to customer.io: ${err.message}`
)
}
CustomerIoHandler.updateUserAttributes(adminUserId, {
email: mongoUserEmail || stripeCustomer.email,
stripe_migration: {
migration_date: migrationDate,
needs_to_update_tax_id: needsToUpdateTaxInfo,
},
})
} catch (err) {
throw new ReportError(
'migrated-customerio-upload-failed',
`Successfully migrated to Stripe but failed to upload user to customer.io: ${err.message}`
)
}
// Step 7: Release subscription schedule associated with the migration
@@ -38,7 +38,6 @@ import { getRegionClient } from '../../modules/subscriptions/app/src/StripeClien
import RecurlyWrapper from '../../app/src/Features/Subscription/RecurlyWrapper.mjs'
import { Subscription } from '../../app/src/models/Subscription.mjs'
import AnalyticsManager from '../../app/src/Features/Analytics/AnalyticsManager.mjs'
import UserAnalyticsIdCache from '../../app/src/Features/Analytics/UserAnalyticsIdCache.mjs'
import CustomerIoHandler from '../../modules/customer-io/app/src/CustomerIoHandler.mjs'
import { ReportError } from './helpers.mjs'
import AccountMappingHelper from '../../app/src/Features/Analytics/AccountMappingHelper.mjs'
@@ -428,18 +427,15 @@ async function performRollback(
}
// Step 5: Remove migration date from customer.io
const analyticsId = await UserAnalyticsIdCache.get(adminUserId)
if (analyticsId) {
try {
CustomerIoHandler.updateUserAttributes(analyticsId, {
stripe_migration: {},
})
} catch (err) {
throw new ReportError(
'rolled-back-customerio-update-failed',
`Restored Mongo, Recurly, Stripe but failed to update user in customer.io: ${err.message}`
)
}
try {
CustomerIoHandler.updateUserAttributes(adminUserId, {
stripe_migration: {},
})
} catch (err) {
throw new ReportError(
'rolled-back-customerio-update-failed',
`Restored Mongo, Recurly, Stripe but failed to update user in customer.io: ${err.message}`
)
}
}