From 69c64b2fc231c6cb1494d815ef8defeb04f09911 Mon Sep 17 00:00:00 2001 From: forehalo Date: Tue, 13 Aug 2024 03:35:38 +0000 Subject: [PATCH] fix(core): checkout event (#7844) --- .../src/hooks/affine/use-subscription-notify.tsx | 2 +- packages/frontend/core/src/mixpanel/events.ts | 3 +++ packages/frontend/core/src/pages/subscribe.tsx | 12 ++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/frontend/core/src/hooks/affine/use-subscription-notify.tsx b/packages/frontend/core/src/hooks/affine/use-subscription-notify.tsx index 07dde99329..555b67d961 100644 --- a/packages/frontend/core/src/hooks/affine/use-subscription-notify.tsx +++ b/packages/frontend/core/src/hooks/affine/use-subscription-notify.tsx @@ -129,7 +129,7 @@ export const useSubscriptionNotifyReader = () => { upgradeNotify(link); localStorage.removeItem(localStorageKey); - track.$.$.$.checkout({ + track.$.settingsPanel.plans.subscribe({ plan, recurring, }); diff --git a/packages/frontend/core/src/mixpanel/events.ts b/packages/frontend/core/src/mixpanel/events.ts index 97f5239f0f..795d0e7d69 100644 --- a/packages/frontend/core/src/mixpanel/events.ts +++ b/packages/frontend/core/src/mixpanel/events.ts @@ -96,6 +96,7 @@ type PaymentEvents = | 'viewPlans' | 'bookDemo' | 'checkout' + | 'subscribe' | 'changeSubscriptionRecurring' | 'confirmChangingSubscriptionRecurring' | 'cancelSubscription' @@ -155,6 +156,7 @@ const PageEvents = { accountSettings: ['uploadAvatar', 'removeAvatar', 'updateUserName'], plans: [ 'checkout', + 'subscribe', 'changeSubscriptionRecurring', 'confirmChangingSubscriptionRecurring', 'cancelSubscription', @@ -346,6 +348,7 @@ export type EventArgs = { oauth: { provider: string }; viewPlans: PaymentEventArgs; checkout: PaymentEventArgs; + subscribe: PaymentEventArgs; cancelSubscription: PaymentEventArgs; confirmCancelingSubscription: PaymentEventArgs; resumeSubscription: PaymentEventArgs; diff --git a/packages/frontend/core/src/pages/subscribe.tsx b/packages/frontend/core/src/pages/subscribe.tsx index a07770cbcf..4c33fba543 100644 --- a/packages/frontend/core/src/pages/subscribe.tsx +++ b/packages/frontend/core/src/pages/subscribe.tsx @@ -70,10 +70,7 @@ export const Component = () => { : !!subscriptionService.subscription.pro$.value; if (!subscribed) { setMessage('Creating checkout...'); - track.subscriptionLanding.$.$.checkout({ - plan: receivedPlan, - recurring: receivedRecurring, - }); + try { const account = authService.session.account$.value; // should never reach @@ -88,6 +85,13 @@ export const Component = () => { : receivedRecurring === 'yearly' ? SubscriptionRecurring.Yearly : SubscriptionRecurring.Lifetime; + + track.subscriptionLanding.$.$.checkout({ + control: 'pricing', + plan: targetPlan, + recurring: targetRecurring, + }); + const checkout = await subscriptionService.createCheckoutSession({ idempotencyKey, plan: targetPlan,