diff --git a/packages/checkout/sdk/src/widgets/definitions/events/sale.ts b/packages/checkout/sdk/src/widgets/definitions/events/sale.ts index ab693e67a5..47dc2fdd59 100644 --- a/packages/checkout/sdk/src/widgets/definitions/events/sale.ts +++ b/packages/checkout/sdk/src/widgets/definitions/events/sale.ts @@ -28,6 +28,8 @@ export type SaleSuccess = { method: string; hash: string | undefined; }[]; + /** THe order reference id, use it to trace order throughout flow */ + transactionId: string; [key: string]: unknown; }; @@ -51,6 +53,8 @@ export type SaleFailed = { method: string; hash: string | undefined; }[]; + /** THe order reference id, use it to trace order throughout flow */ + transactionId: string; }; /** diff --git a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetEvents.ts b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetEvents.ts index 4f98dbbf33..3220bf7201 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetEvents.ts +++ b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetEvents.ts @@ -27,6 +27,7 @@ export const sendSaleSuccessEvent = ( paymentMethod: SalePaymentTypes | undefined, transactions: ExecutedTransaction[] = [], tokenIds: string[] = [], + transactionId: string = '', ) => { const event = new CustomEvent< WidgetEvent @@ -37,6 +38,7 @@ export const sendSaleSuccessEvent = ( paymentMethod, transactions, tokenIds, + transactionId, }, }, }); @@ -51,6 +53,7 @@ export const sendSaleFailedEvent = ( error: Record, paymentMethod: SalePaymentTypes | undefined, transactions: ExecutedTransaction[] = [], + transactionId: string = '', ) => { const event = new CustomEvent< WidgetEvent @@ -62,6 +65,7 @@ export const sendSaleFailedEvent = ( error, paymentMethod, transactions, + transactionId, timestamp: new Date().getTime(), }, }, diff --git a/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSaleEvents.ts b/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSaleEvents.ts index 1c8ee1e28e..2b7a5c501b 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSaleEvents.ts +++ b/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSaleEvents.ts @@ -67,7 +67,7 @@ export const useSaleEvent = () => { screen: string = defaultView, transactions: ExecutedTransaction[] = [], tokenIds: string[] = [], - details?: Record, + details: Record = {}, ) => { track({ ...commonProps, @@ -84,7 +84,7 @@ export const useSaleEvent = () => { tokenIds, }, }); - sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds); + sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds, details.transactionId); }; const sendFailedEvent = ( @@ -92,14 +92,16 @@ export const useSaleEvent = () => { error: Record, transactions: ExecutedTransaction[] = [], screen: string = defaultView, + details: Record = {}, ) => { track({ ...commonProps, - screen: toPascalCase(screen), + screen: toPascalCase(screen || defaultView), control: 'Fail', controlType: 'Event', action: 'Failed', extras: { + ...details, transactions: toStringifyTransactions(transactions), ...error, ...orderProps, @@ -108,7 +110,7 @@ export const useSaleEvent = () => { reason, }, }); - sendSaleFailedEvent(eventTarget, reason, error, paymentMethod, transactions); + sendSaleFailedEvent(eventTarget, reason, error, paymentMethod, transactions, details.transactionId); }; const sendTransactionSuccessEvent = (transaction: ExecutedTransaction) => { diff --git a/packages/checkout/widgets-lib/src/widgets/sale/views/PayWithCoins.tsx b/packages/checkout/widgets-lib/src/widgets/sale/views/PayWithCoins.tsx index 5e8da7aa2a..133f7d45fb 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/views/PayWithCoins.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/views/PayWithCoins.tsx @@ -43,7 +43,8 @@ export function PayWithCoins() { sendTransactionSuccessEvent(txn); }, (error, txns) => { - sendFailedEvent(error.toString(), error, txns); + const details = { transactionId: signResponse?.transactionId }; + sendFailedEvent(error.toString(), error, txns, undefined, details); }, ); };