From 6e1e33440654e64f136121e1a8cfea66fff54f7d Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 16 May 2025 03:53:34 +0600 Subject: [PATCH] feat: add ai tutor gtags (#8656) * feat: add ai tutor gtags * fix: price id condition check --- .../Billing/UpdatePlanConfirmation.tsx | 10 ++--- .../Billing/UpgradeAccountModal.tsx | 39 +++++++++++++++---- src/components/Billing/VerifyUpgrade.tsx | 33 +++++++++++++++- src/components/GenerateCourse/AICourse.tsx | 8 ++++ 4 files changed, 76 insertions(+), 14 deletions(-) diff --git a/src/components/Billing/UpdatePlanConfirmation.tsx b/src/components/Billing/UpdatePlanConfirmation.tsx index 78cc041de..c14952f04 100644 --- a/src/components/Billing/UpdatePlanConfirmation.tsx +++ b/src/components/Billing/UpdatePlanConfirmation.tsx @@ -62,8 +62,8 @@ export function UpdatePlanConfirmation(props: UpdatePlanConfirmationProps) {

Subscription Update

Your plan will be updated to the{' '} - {planDetails.interval} plan, and will - be charged{' '} + {planDetails.interval} plan, and will be + charged{' '} ${selectedPrice.amount}/{selectedPrice.interval} @@ -72,21 +72,21 @@ export function UpdatePlanConfirmation(props: UpdatePlanConfirmationProps) {

diff --git a/src/components/Billing/UpgradeAccountModal.tsx b/src/components/Billing/UpgradeAccountModal.tsx index b187b7ab3..99cb73ed8 100644 --- a/src/components/Billing/UpgradeAccountModal.tsx +++ b/src/components/Billing/UpgradeAccountModal.tsx @@ -136,6 +136,14 @@ export function UpgradeAccountModal(props: UpgradeAccountModalProps) { setSelectedPlan(currentPlan.interval); }, [currentPlan]); + useEffect(() => { + window?.fireEvent({ + action: 'tutor_pricing', + category: 'ai_tutor', + label: 'Clicked Upgrade to Pro', + }); + }, []); + if (!user) { return null; } @@ -262,18 +270,35 @@ export function UpgradeAccountModal(props: UpgradeAccountModalProps) { } onClick={() => { setSelectedPlan(plan.interval); + if (!currentPlanPriceId) { const currentUrlPath = window.location.pathname; - const encodedCurrentUrlPath = encodeURIComponent( - currentUrlPath, - ); + const encodedCurrentUrlPath = + encodeURIComponent(currentUrlPath); const successPage = `/thank-you?next=${encodedCurrentUrlPath}&s=1`; - createCheckoutSession({ - priceId: plan.priceId, - success: success || successPage, - cancel: cancel || `${currentUrlPath}?s=0`, + window?.fireEvent({ + action: 'tutor_checkout', + category: 'ai_tutor', + label: 'Checkout Started', }); + + createCheckoutSession( + { + priceId: plan.priceId, + success: success || successPage, + cancel: cancel || `${currentUrlPath}?s=0`, + }, + { + onSuccess: () => { + window?.fireEvent({ + action: `tutor_checkout_${plan.interval === 'month' ? 'mo' : 'an'}`, + category: 'ai_tutor', + label: `${plan.interval} Plan Checkout Started`, + }); + }, + }, + ); return; } setIsUpdatingPlan(true); diff --git a/src/components/Billing/VerifyUpgrade.tsx b/src/components/Billing/VerifyUpgrade.tsx index f59105fd0..85b0142ab 100644 --- a/src/components/Billing/VerifyUpgrade.tsx +++ b/src/components/Billing/VerifyUpgrade.tsx @@ -30,11 +30,40 @@ export function VerifyUpgrade(props: VerifyUpgradeProps) { userBillingDetails.status === 'active' && (newPriceId ? userBillingDetails.priceId === newPriceId : true) ) { + if (!newPriceId) { + // it means that the user is subscribing for the first time + // not changing the plan + window?.fireEvent({ + action: `tutor_purchase_${userBillingDetails.interval === 'month' ? 'mo' : 'an'}`, + category: 'ai_tutor', + label: `${userBillingDetails.interval} Plan Purchased`, + }); + } + deleteUrlParam('s'); window.location.reload(); } }, [userBillingDetails]); + useEffect(() => { + // it means that the user is changing the plan + // not subscribing for the first time + if (newPriceId) { + return; + } + + window?.fireEvent({ + action: 'tutor_purchase', + category: 'ai_tutor', + label: 'Subscription Activated', + }); + window?.fireEvent({ + action: 'tutor_ty', + category: 'ai_tutor', + label: 'Thank You Page Visited', + }); + }, [newPriceId]); + return ( Subscription Activated
-

+

Your subscription has been activated successfully.

-

+

It might take a minute for the changes to reflect. We will{' '} reload the page for you.

diff --git a/src/components/GenerateCourse/AICourse.tsx b/src/components/GenerateCourse/AICourse.tsx index ccbd23a65..e0c5fca47 100644 --- a/src/components/GenerateCourse/AICourse.tsx +++ b/src/components/GenerateCourse/AICourse.tsx @@ -51,6 +51,14 @@ export function AICourse(props: AICourseProps) { setCustomInstructions(fineTuneData.customInstructions); }, []); + useEffect(() => { + window?.fireEvent({ + action: 'tutor_user', + category: 'ai_tutor', + label: 'Visited AI Course Page', + }); + }, []); + const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && keyword.trim()) { onSubmit();