From 0b8fcb067af72fb46303d649ceabcb1b28e7fe5f Mon Sep 17 00:00:00 2001 From: katspaugh Date: Fri, 10 Nov 2023 11:31:13 +0100 Subject: [PATCH] Track only typed messages as tx_created --- .../tx-flow/flows/SignMessage/SignMessage.tsx | 19 +++++++++++-------- .../ReviewSignMessageOnChain.tsx | 5 ++++- src/hooks/messages/useSafeMsgTracking.ts | 5 ----- src/services/analytics/events/transactions.ts | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/tx-flow/flows/SignMessage/SignMessage.tsx b/src/components/tx-flow/flows/SignMessage/SignMessage.tsx index d331e10b96..dfd2cd79a9 100644 --- a/src/components/tx-flow/flows/SignMessage/SignMessage.tsx +++ b/src/components/tx-flow/flows/SignMessage/SignMessage.tsx @@ -38,6 +38,8 @@ import InfoBox from '@/components/safe-messages/InfoBox' import { DecodedMsg } from '@/components/safe-messages/DecodedMsg' import TxCard from '@/components/tx-flow/common/TxCard' import { dispatchPreparedSignature } from '@/services/safe-messages/safeMsgNotifications' +import { trackEvent } from '@/services/analytics' +import { TX_EVENTS, TX_TYPES } from '@/services/analytics/events/transactions' const createSkeletonMessage = (confirmationsRequired: number): SafeMessage => { return { @@ -169,19 +171,14 @@ const SignMessage = ({ message, safeAppId, requestId }: ProposeProps | ConfirmPr const { safe } = useSafeInfo() const isOwner = useIsSafeOwner() const wallet = useWallet() + useHighlightHiddenTab() const { decodedMessage, safeMessageMessage, safeMessageHash } = useDecodedSafeMessage(message, safe) const [safeMessage, setSafeMessage] = useSafeMessage(safeMessageHash) - - useHighlightHiddenTab() - - const decodedMessageAsString = - typeof decodedMessage === 'string' ? decodedMessage : JSON.stringify(decodedMessage, null, 2) - + const isPlainTextMessage = typeof decodedMessage === 'string' + const decodedMessageAsString = isPlainTextMessage ? decodedMessage : JSON.stringify(decodedMessage, null, 2) const hasSigned = !!safeMessage?.confirmations.some(({ owner }) => owner.value === wallet?.address) - const isFullySigned = !!safeMessage?.preparedSignature - const isDisabled = !isOwner || hasSigned const { onSign, submitError } = useSyncSafeMessageSigner( @@ -195,9 +192,15 @@ const SignMessage = ({ message, safeAppId, requestId }: ProposeProps | ConfirmPr const handleSign = async () => { const updatedMessage = await onSign() + if (updatedMessage) { setSafeMessage(updatedMessage) } + + // Track first signature as creation + if (updatedMessage?.confirmations.length === 1) { + trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.typed_message }) + } } const onContinue = async () => { diff --git a/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx b/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx index 378b296979..d940608ac5 100644 --- a/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx +++ b/src/components/tx-flow/flows/SignMessageOnChain/ReviewSignMessageOnChain.tsx @@ -101,7 +101,10 @@ const ReviewSignMessageOnChain = ({ message, method, requestId }: SignMessageOnC const handleSubmit = async () => { if (!safeTx || !onboard) return - trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.message }) + // Track the creation of a typed message + if (isTypedMessage && safeTx.signatures.size === 1) { + trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.typed_message }) + } try { await dispatchSafeAppsTx(safeTx, requestId, onboard, safe.chainId) diff --git a/src/hooks/messages/useSafeMsgTracking.ts b/src/hooks/messages/useSafeMsgTracking.ts index 8e1131ccbf..45b3bf6fae 100644 --- a/src/hooks/messages/useSafeMsgTracking.ts +++ b/src/hooks/messages/useSafeMsgTracking.ts @@ -2,7 +2,6 @@ import { useEffect } from 'react' import { trackEvent, WALLET_EVENTS } from '@/services/analytics' import { SafeMsgEvent, safeMsgSubscribe } from '@/services/safe-messages/safeMsgEvents' -import { TX_EVENTS, TX_TYPES } from '@/services/analytics/events/transactions' const safeMsgEvents = { [SafeMsgEvent.PROPOSE]: WALLET_EVENTS.SIGN_MESSAGE, @@ -14,10 +13,6 @@ export const useSafeMsgTracking = (): void => { const unsubFns = Object.entries(safeMsgEvents).map(([safeMsgEvent, analyticsEvent]) => safeMsgSubscribe(safeMsgEvent as SafeMsgEvent, () => { trackEvent(analyticsEvent) - - if (analyticsEvent === WALLET_EVENTS.SIGN_MESSAGE) { - trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.message }) - } }), ) diff --git a/src/services/analytics/events/transactions.ts b/src/services/analytics/events/transactions.ts index df6503e367..09b94763e4 100644 --- a/src/services/analytics/events/transactions.ts +++ b/src/services/analytics/events/transactions.ts @@ -22,7 +22,7 @@ export enum TX_TYPES { // Other batch = 'batch', rejection = 'rejection', - message = 'message', + typed_message = 'typed_message', safeapps = 'safeapps', walletconnect = 'walletconnect', }