11import { usePollGetOrderPublic } from "../../../../queries/usePollGetOrderPublic.ts" ;
22import { useNavigate , useParams } from "react-router" ;
3- import { useEffect , useState } from "react" ;
3+ import { useEffect , useRef , useState } from "react" ;
44import classes from './PaymentReturn.module.scss' ;
55import { t } from "@lingui/macro" ;
66import { useGetOrderStripePaymentIntentPublic } from "../../../../queries/useGetOrderStripePaymentIntentPublic.ts" ;
77import { CheckoutContent } from "../../../layouts/Checkout/CheckoutContent" ;
88import { eventCheckoutPath } from "../../../../utilites/urlHelper.ts" ;
99import { HomepageInfoMessage } from "../../../common/HomepageInfoMessage" ;
1010import { isSsr } from "../../../../utilites/helpers.ts" ;
11+ import { trackEvent , AnalyticsEvents } from "../../../../utilites/analytics.ts" ;
1112
1213/**
1314 * This component is responsible for handling the return from the payment provider.
@@ -24,6 +25,7 @@ export const PaymentReturn = () => {
2425 const [ attemptManualConfirmation , setAttemptManualConfirmation ] = useState ( false ) ;
2526 const paymentIntentQuery = useGetOrderStripePaymentIntentPublic ( eventId , orderShortId , attemptManualConfirmation ) ;
2627 const [ cannotConfirmPayment , setCannotConfirmPayment ] = useState ( false ) ;
28+ const hasTrackedPurchase = useRef ( false ) ;
2729
2830 useEffect (
2931 ( ) => {
@@ -44,6 +46,11 @@ export const PaymentReturn = () => {
4446 return ;
4547 }
4648 if ( paymentIntentQuery . data ?. status === 'succeeded' ) {
49+ if ( ! hasTrackedPurchase . current && order ) {
50+ hasTrackedPurchase . current = true ;
51+ const totalCents = Math . round ( ( order . total_gross || 0 ) * 100 ) ;
52+ trackEvent ( AnalyticsEvents . PURCHASE_COMPLETED_PAID , { value : totalCents } ) ;
53+ }
4754 navigate ( eventCheckoutPath ( eventId , orderShortId , 'summary' ) ) ;
4855 } else {
4956 // At this point we've tried multiple times to confirm the payment and failed.
@@ -59,6 +66,11 @@ export const PaymentReturn = () => {
5966 }
6067
6168 if ( order ?. status === 'COMPLETED' ) {
69+ if ( ! hasTrackedPurchase . current ) {
70+ hasTrackedPurchase . current = true ;
71+ const totalCents = Math . round ( ( order . total_gross || 0 ) * 100 ) ;
72+ trackEvent ( AnalyticsEvents . PURCHASE_COMPLETED_PAID , { value : totalCents } ) ;
73+ }
6274 navigate ( eventCheckoutPath ( eventId , orderShortId , 'summary' ) ) ;
6375 }
6476 if ( order ?. payment_status === 'PAYMENT_FAILED' || ( typeof window !== 'undefined' && window ?. location . search . includes ( 'failed' ) ) ) {
0 commit comments