Skip to content

Commit

Permalink
update sale success/error events
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesgodi committed Mar 15, 2024
1 parent b025cfe commit 16bbdc2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/checkout/sdk/src/widgets/definitions/events/sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const sendSaleSuccessEvent = (
paymentMethod: SalePaymentTypes | undefined,
transactions: ExecutedTransaction[] = [],
tokenIds: string[] = [],
transactionId: string = '',
) => {
const event = new CustomEvent<
WidgetEvent<WidgetType.SALE, SaleEventType.SUCCESS>
Expand All @@ -37,6 +38,7 @@ export const sendSaleSuccessEvent = (
paymentMethod,
transactions,
tokenIds,
transactionId,
},
},
});
Expand All @@ -51,6 +53,7 @@ export const sendSaleFailedEvent = (
error: Record<string, unknown>,
paymentMethod: SalePaymentTypes | undefined,
transactions: ExecutedTransaction[] = [],
transactionId: string = '',
) => {
const event = new CustomEvent<
WidgetEvent<WidgetType.SALE, SaleEventType.FAILURE>
Expand All @@ -62,6 +65,7 @@ export const sendSaleFailedEvent = (
error,
paymentMethod,
transactions,
transactionId,
timestamp: new Date().getTime(),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useSaleEvent = () => {
screen: string = defaultView,
transactions: ExecutedTransaction[] = [],
tokenIds: string[] = [],
details?: Record<string, unknown>,
details: Record<string, any> = {},
) => {
track({
...commonProps,
Expand All @@ -84,22 +84,24 @@ export const useSaleEvent = () => {
tokenIds,
},
});
sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds);
sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds, details.transactionId);
};

const sendFailedEvent = (
reason: string,
error: Record<string, unknown>,
transactions: ExecutedTransaction[] = [],
screen: string = defaultView,
details: Record<string, any> = {},
) => {
track({
...commonProps,
screen: toPascalCase(screen),
screen: toPascalCase(screen || defaultView),
control: 'Fail',
controlType: 'Event',
action: 'Failed',
extras: {
...details,
transactions: toStringifyTransactions(transactions),
...error,
...orderProps,
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
};
Expand Down

0 comments on commit 16bbdc2

Please sign in to comment.