diff --git a/packages/apps/rwa-demo/src/components/TransactionsProvider/TransactionsProvider.tsx b/packages/apps/rwa-demo/src/components/TransactionsProvider/TransactionsProvider.tsx index 8a4e1b213f..013e8b046f 100644 --- a/packages/apps/rwa-demo/src/components/TransactionsProvider/TransactionsProvider.tsx +++ b/packages/apps/rwa-demo/src/components/TransactionsProvider/TransactionsProvider.tsx @@ -3,6 +3,7 @@ import type { IWalletAccount } from '@/components/AccountProvider/AccountType'; import { useAccount } from '@/hooks/account'; import { useNetwork } from '@/hooks/networks'; import { transactionsQuery } from '@/services/graph/transactionSubscription.graph'; +import { analyticsEvent } from '@/utils/analytics'; import { store } from '@/utils/store'; import { useApolloClient } from '@apollo/client'; import type { ICommandResult } from '@kadena/client'; @@ -56,6 +57,8 @@ export interface ITransaction { uuid: string; requestKey: string; type: ITxType; + chainId?: string; + networkId?: string; listener?: any; accounts: string[]; result?: ICommandResult['result']; @@ -137,6 +140,15 @@ export const TransactionsProvider: FC = ({ children }) => { nextData?.errors?.length !== undefined || nextData?.data?.transaction?.result.badResult ) { + analyticsEvent(`error:${data.type.name}`, { + name: data.type.name, + chainId: data?.chainId ?? '', + networkId: data?.networkId ?? '', + requestKey: data?.requestKey ?? '', + message: JSON.stringify( + nextData?.data.transaction?.result.badResult, + ), + }); addNotification({ intent: 'negative', label: 'there was an error', @@ -153,6 +165,14 @@ export const TransactionsProvider: FC = ({ children }) => { } }, (errorData) => { + analyticsEvent(`error:${data.type.name}`, { + name: data.type.name, + chainId: data?.chainId ?? '', + networkId: data?.networkId ?? '', + requestKey: data?.requestKey ?? '', + message: JSON.stringify(errorData), + }); + addNotification({ intent: 'negative', label: 'there was an error', @@ -161,6 +181,12 @@ export const TransactionsProvider: FC = ({ children }) => { }); }, () => { + analyticsEvent(data.type.name, { + chainId: data?.chainId ?? '', + networkId: data?.networkId ?? '', + requestKey: data?.requestKey ?? '', + message: data?.result?.status, + }); // eslint-disable-next-line @typescript-eslint/no-floating-promises store.removeTransaction(data); }, @@ -252,8 +278,6 @@ export const TransactionsProvider: FC = ({ children }) => { setTxsAnimationRefData(ref); }; - console.log({ transactions }); - return ( { - console.log({ data }); data?.events?.map(({ parameters }: any) => { const params = JSON.parse(parameters); const fromAccount = params.length > 1 && params[0]; diff --git a/packages/apps/rwa-demo/src/utils/__tests__/analytics.test.ts b/packages/apps/rwa-demo/src/utils/__tests__/analytics.test.ts index d882c95f90..09bd49f9d3 100644 --- a/packages/apps/rwa-demo/src/utils/__tests__/analytics.test.ts +++ b/packages/apps/rwa-demo/src/utils/__tests__/analytics.test.ts @@ -94,15 +94,20 @@ describe('analytics', () => { describe('analyticsEvent', () => { it('should call analyticsEvent with correct props', () => { - analyticsEvent(EVENT_NAMES['click:search'], { + analyticsEvent(EVENT_NAMES['error:submitChain'], { label: 'Master of the universe', hash: '/he-man', }); - expect(window.gtag).toHaveBeenNthCalledWith(1, 'event', 'click:search', { - hash: '/he-man', - label: 'Master of the universe', - }); + expect(window.gtag).toHaveBeenNthCalledWith( + 1, + 'event', + 'error:submitChain', + { + hash: '/he-man', + label: 'Master of the universe', + }, + ); }); it('should also console.warn when the nodeenv is development', () => { @@ -111,19 +116,24 @@ describe('analytics', () => { .mockImplementation(() => undefined); vi.stubEnv('NODE_ENV', 'development'); - analyticsEvent(EVENT_NAMES['click:search'], { + analyticsEvent(EVENT_NAMES['error:submitChain'], { label: 'Master of the universe', hash: '/he-man', }); expect(consoleMock).toBeCalledWith('GTAG EVENT', { - name: 'click:search', + name: 'error:submitChain', options: { hash: '/he-man', label: 'Master of the universe' }, }); - expect(window.gtag).toHaveBeenNthCalledWith(1, 'event', 'click:search', { - hash: '/he-man', - label: 'Master of the universe', - }); + expect(window.gtag).toHaveBeenNthCalledWith( + 1, + 'event', + 'error:submitChain', + { + hash: '/he-man', + label: 'Master of the universe', + }, + ); }); }); }); diff --git a/packages/apps/rwa-demo/src/utils/analytics.ts b/packages/apps/rwa-demo/src/utils/analytics.ts index 9c4f1df989..7a89403284 100644 --- a/packages/apps/rwa-demo/src/utils/analytics.ts +++ b/packages/apps/rwa-demo/src/utils/analytics.ts @@ -1,6 +1,8 @@ +import type { TXTYPES } from '@/components/TransactionsProvider/TransactionsProvider'; + // eslint-disable-next-line @kadena-dev/typedef-var export const EVENT_NAMES = { - 'click:search': 'click:search', + 'error:submitChain': 'error:submitChain', } as const; const COOKIE_CONSENTNAME = 'cookie_consent'; @@ -13,7 +15,10 @@ interface IOptionsPageViewType { } export const analyticsEvent = ( - name: keyof typeof EVENT_NAMES, + name: + | keyof typeof EVENT_NAMES + | keyof typeof TXTYPES + | `error:${keyof typeof TXTYPES}`, options: IOptionsType = {}, ): void => { if (process.env.NODE_ENV === 'development') {