From a46fef3ec0a257d18c966b781cc2b023cb5e4e5b Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Mon, 28 Apr 2025 12:39:39 +0200 Subject: [PATCH] Add "referrer" tracking to payment flows for AI assist (#25002) * Add "referrer" tracking to payment flows for AI assist * move sendMB call * fix conflict GitOrigin-RevId: 0c4480816d5fe525a87223c0b1827093d853d474 --- .../Subscription/SubscriptionController.js | 6 +++++- .../views/subscriptions/preview-change.pug | 1 + .../preview-subscription-change/root.tsx | 21 ++++++++++++++++++- services/web/frontend/js/utils/meta.ts | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 4cc4c7e9f7..d3657ca026 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -314,6 +314,7 @@ function cancelV1Subscription(req, res, next) { async function previewAddonPurchase(req, res) { const userId = SessionManager.getLoggedInUserId(req.session) const addOnCode = req.params.addOnCode + const purchaseReferrer = req.query.purchaseReferrer if (addOnCode !== AI_ADD_ON_CODE) { return HttpErrorHandler.notFound(req, res, `Unknown add-on: ${addOnCode}`) @@ -363,7 +364,10 @@ async function previewAddonPurchase(req, res) { paymentMethod ) - res.render('subscriptions/preview-change', { changePreview }) + res.render('subscriptions/preview-change', { + changePreview, + purchaseReferrer, + }) } async function purchaseAddon(req, res, next) { diff --git a/services/web/app/views/subscriptions/preview-change.pug b/services/web/app/views/subscriptions/preview-change.pug index ab70d2d6b6..663bbe30d2 100644 --- a/services/web/app/views/subscriptions/preview-change.pug +++ b/services/web/app/views/subscriptions/preview-change.pug @@ -5,6 +5,7 @@ block entrypointVar block append meta meta(name="ol-subscriptionChangePreview" data-type="json" content=changePreview) + meta(name="ol-purchaseReferrer" data-type="string" content=purchaseReferrer) block content main.content.content-alt#main-content diff --git a/services/web/frontend/js/features/subscription/components/preview-subscription-change/root.tsx b/services/web/frontend/js/features/subscription/components/preview-subscription-change/root.tsx index 4d5746a411..513b1b14ba 100644 --- a/services/web/frontend/js/features/subscription/components/preview-subscription-change/root.tsx +++ b/services/web/frontend/js/features/subscription/components/preview-subscription-change/root.tsx @@ -25,19 +25,38 @@ function PreviewSubscriptionChange() { const preview = getMeta( 'ol-subscriptionChangePreview' ) as SubscriptionChangePreview + const purchaseReferrer = getMeta('ol-purchaseReferrer') const { t } = useTranslation() const payNowTask = useAsync() const location = useLocation() const handlePayNowClick = useCallback(() => { + let addOnSegmentation: Record | null = null + if (preview.change.type === 'add-on-purchase') { + addOnSegmentation = { + addOn: preview.change.addOn.code, + upgradeType: 'add-on', + } + if (purchaseReferrer) { + addOnSegmentation.referrer = purchaseReferrer + } + eventTracking.sendMB('subscription-change-form-submit', addOnSegmentation) + } + eventTracking.sendMB('assistant-add-on-purchase') payNowTask .runAsync(payNow(preview)) .then(() => { + if (addOnSegmentation) { + eventTracking.sendMB( + 'subscription-change-form-success', + addOnSegmentation + ) + } location.replace('/user/subscription/thank-you') }) .catch(debugConsole.error) - }, [location, payNowTask, preview]) + }, [purchaseReferrer, location, payNowTask, preview]) const aiAddOnChange = preview.change.type === 'add-on-purchase' && diff --git a/services/web/frontend/js/utils/meta.ts b/services/web/frontend/js/utils/meta.ts index 6f2fe864f9..f502143818 100644 --- a/services/web/frontend/js/utils/meta.ts +++ b/services/web/frontend/js/utils/meta.ts @@ -187,6 +187,7 @@ export interface Meta { 'ol-projectSyncSuccessMessage': string 'ol-projectTags': Tag[] 'ol-project_id': string + 'ol-purchaseReferrer': string 'ol-recommendedCurrency': CurrencyCode 'ol-reconfirmationRemoveEmail': string 'ol-reconfirmedViaSAML': string