import type { QuoteMode } from '../../../domains/quoteMode'; import type { DirectExecutionType, FormOfPaymentType } from '@funkit/api-base'; import type { CheckoutStatus } from '../../../domains/checkout'; import type { PaymentMethodType } from '../../../hooks/usePaymentSources'; import type { FunCheckoutStep } from '../../../modals/CheckoutModal/FunCheckoutStep'; import type { AmountSelectionType } from '../../../modals/CheckoutModal/InputAmount/state'; import type { WithdrawalModalStep } from '../../../modals/WithdrawalModal/types'; import type { FunNotificationType } from '../../../components/FunNotification/FunNotification'; import type { PaymentMethod } from '@funkit/connect-core'; /** * Analytics v2 — the improved, explicit Statsig event scheme that will replace * the `fc::`/`fw::` enums in `../CheckoutModalEvent.ts` / `../WithdrawModalEvent.ts`. * Every property is explicitly assigned so each emitted payload is auditable. */ export declare enum AnalyticsEvent { DEPOSIT_ASSET_SELECTED = "fc_deposit_asset_selected", DEPOSIT_AMOUNT_CONFIRMED = "fc_deposit_amount_confirmed", DEPOSIT_FAILED = "fc_deposit_failed", DEPOSIT_METHOD_SELECTED = "fc_deposit_method_selected", DEPOSIT_NOTIFICATION_DISPLAYED = "fc_deposit_notification_displayed", DEPOSIT_NOTIFICATION_INTERACTED = "fc_deposit_notification_interacted", DEPOSIT_QUOTE_DISPLAYED = "fc_deposit_quote_displayed", DEPOSIT_QUOTE_CONFIRMED = "fc_deposit_quote_confirmed", DEPOSIT_SUCCEEDED = "fc_deposit_succeeded", DEPOSIT_TRANSFER_INTERACTED = "fc_deposit_transfer_interacted", DEPOSIT_TRANSACTION_BREAKDOWN_CLICKED = "fc_deposit_transaction_breakdown_clicked", DEPOSIT_TRANSACTION_SUBMITTED = "fc_deposit_transaction_submitted", ERROR_SHOWN = "fc_error_shown", IFRAME_STEP_VIEWED = "fc_iframe_step_viewed", MODAL_CLOSED = "fc_modal_closed", MODAL_OPENED = "fc_modal_opened", PERF_IFRAME_READY = "fc_perf_iframe_ready", PERF_QUOTE = "fc_perf_quote", PERF_STEP_READY = "fc_perf_step_ready", STEP_VIEWED = "fc_step_viewed", TAB_SWITCHED = "fc_tab_switched", WITHDRAWAL_AMOUNT_CONFIRMED = "fc_withdrawal_amount_confirmed", WITHDRAWAL_FAILED = "fc_withdrawal_failed", WITHDRAWAL_METHOD_SELECTED = "fc_withdrawal_method_selected", WITHDRAWAL_QUOTE_DISPLAYED = "fc_withdrawal_quote_displayed", WITHDRAWAL_QUOTE_CONFIRMED = "fc_withdrawal_quote_confirmed", WITHDRAWAL_SUCCEEDED = "fc_withdrawal_succeeded", WITHDRAWAL_TRANSACTION_BREAKDOWN_CLICKED = "fc_withdrawal_transaction_breakdown_clicked", WITHDRAWAL_TRANSFER_INTERACTED = "fc_withdrawal_transfer_interacted", WITHDRAWAL_TRANSACTION_SUBMITTED = "fc_withdrawal_transaction_submitted" } export type ConnectionStatus = 'new' | 'existing'; export type AnalyticsFlow = 'deposit' | 'withdraw' | 'convert'; export type AnalyticsPaymentRail = 'swapped' | 'meld' | 'bridge'; export type AnalyticsStep = Lowercase; export type ModalClosedAction = 'close' | 'new_deposit' | 'new_withdrawal'; export type ModalCompletionState = 'completed' | 'not_completed' | 'undetected'; /** Envelope carried by every analytics-v2 event. */ export type CommonProperties = { /** * Short customer_id/customer_name are not readily available on the frontend, * so pass the api_key in the meantime just like the existing events. */ api_key: string; /** * Primary key correlating all events in one checkout. Kept in the shared * type even though it's assigned per event (not in a shared "common * properties" object) — some events (e.g. a persisted succeeded/failed * record) need to source it from historical context rather than the * currently active checkout. */ checkout_id: string; /** Raw routing identity selected for this checkout, when available. */ dynamic_routing_id: string | null; /** Human-readable connector name for the authenticated session wallet. */ connector_name: string | null; flow: AnalyticsFlow; /** Fixed per package — distinguishes this SDK's events from connect-rn's. */ sdk_type: 'web'; user_id: string | null; }; export type PaymentMethodProperties = { /** Payment method as defined by the checkout domain. */ payment_method: string; /** Checkout provider identity; null when not applicable or authoritative. */ provider: string | null; }; export type ErrorProperties = { error_code: string | null; error_message: string | null; }; export type ErrorShownProperties = ErrorProperties & { /** Provider order associated with an embedded checkout error. */ order_id?: string | null; flow: AnalyticsFlow; notification_type: FunNotificationType; step: AnalyticsStep; }; /** Source/target/payment context shared by the deposit events. */ export type DepositAssetContextProperties = PaymentMethodProperties & { source_chain: string | null; source_asset: string | null; source_asset_ticker: string | null; target_chain: string; target_asset: string; target_asset_ticker: string | null; }; /** Payload specific to {@link AnalyticsEvent.DEPOSIT_ASSET_SELECTED}. */ export type DepositAssetSelectedProperties = DepositAssetContextProperties & { /** 0-based index of the chosen asset in the displayed list; `-1` if unresolved. */ asset_position: number; /** Whether the chosen chain/token pair matches the flow's resolved default. */ is_default_token: boolean; }; /** Payload specific to {@link AnalyticsEvent.DEPOSIT_AMOUNT_CONFIRMED}. */ export type DepositAmountConfirmedProperties = DepositAssetContextProperties & { /** * The quick option / recovery amount the user picked, formatted exactly as * shown on its button (e.g. `"25%"`, `"$100"`). `null` when `select_type` * is not `'preset'`. */ preset_amount: string | null; select_type: AmountSelectionType; /** * Source token amount the user pays — exact in EXACT_IN, estimated in * EXACT_OUT. `null` when the estimate's unit price is unavailable. */ source_amount: string | null; /** * Target token amount received — exact in EXACT_OUT, estimated in EXACT_IN. * `null` when the estimate's unit price is unavailable. */ target_amount: string | null; trade_type: QuoteMode; }; export type WithdrawalAmountSelectionType = 'manual' | 'max'; /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_AMOUNT_CONFIRMED}. */ export type WithdrawalAmountConfirmedProperties = PaymentMethodProperties & { select_type: WithdrawalAmountSelectionType; source_amount: string | null; source_chain: string; source_asset: string; source_asset_ticker: string | null; target_amount: string | null; target_chain: string; target_asset: string; target_asset_ticker: string | null; trade_type: QuoteMode.EXACT_IN; }; /** Payload specific to {@link AnalyticsEvent.DEPOSIT_METHOD_SELECTED}. */ export type DepositMethodSelectedProperties = DepositAssetContextProperties & { connection_status: ConnectionStatus | null; payment_rail: AnalyticsPaymentRail | null; tab: PaymentMethodType | null; }; /** Fee rows rendered by PaymentFeesSummary for a displayed quote. */ export type VisibleQuoteFeeProperties = { app_fee_pct: number | null; destination_chain_gas_usd: number | null; card_processing_fee_usd: number | null; exchange_processing_fee_usd: number | null; liquidity_provider_cost_usd: number | null; market_maker_gas_cost_usd: number | null; max_slippage_pct: number | null; moonpay_cost_usd: number | null; network_cost_usd: number | null; /** Total impact shown to the user; quote-backed values include app fees. */ price_impact_pct: number | null; source_chain_gas_usd: number | null; /** Quote provider's swap-only component; null without compatible quote metadata. */ swap_impact_pct: number | null; wallet_gas_cost_usd: number | null; }; /** Payload emitted when the user manually expands a transaction breakdown. */ export type TransactionBreakdownClickedProperties = PaymentMethodProperties & VisibleQuoteFeeProperties & { step: AnalyticsStep; }; /** Route fields shared by quote-bearing and later lifecycle events. */ export type DepositRouteContextProperties = DepositAssetContextProperties & { destination_address: string | null; execution_type: DirectExecutionType | null; sender_address: string | null; trade_type: QuoteMode; }; /** Quote fields shared across quote-lifecycle and submission events. */ export type DepositQuoteSnapshotProperties = DepositRouteContextProperties & VisibleQuoteFeeProperties & { /** Estimated fulfillment time in milliseconds. */ est_fulfillment_time_ms: number | null; source_amount: string; target_amount: string | null; }; /** Quote snapshot plus quote-lifecycle metadata. */ export type DepositQuoteContextProperties = DepositQuoteSnapshotProperties & { num_quote_refreshes: number; /** Routing quote ID; null for provider-only quotes such as Meld. */ quote_id: string | null; }; /** Payload specific to {@link AnalyticsEvent.DEPOSIT_QUOTE_DISPLAYED}. */ export type DepositQuoteDisplayedProperties = DepositQuoteContextProperties; /** Payload specific to {@link AnalyticsEvent.DEPOSIT_QUOTE_CONFIRMED}. */ export type DepositQuoteConfirmedProperties = DepositQuoteContextProperties; /** * Submitted execution snapshot with values preserved at their historical * authority. Persisted records cannot always recover a trade direction, * quote, source asset, or broadcast hash. */ export type ExecutionTransactionSnapshotProperties = DepositAssetContextProperties & VisibleQuoteFeeProperties & { checkout_id: string; destination_address: string | null; execution_type: DirectExecutionType | null; sender_address: string | null; source_amount: string | null; target_amount: string | null; trade_type: QuoteMode | null; tx_hash: string | null; user_id?: string; }; export type TransactionSubmittedProperties = Omit & { target_chain: string | null; target_asset: string | null; est_fulfillment_time_ms: number | null; quote_id: string | null; payment_rail?: AnalyticsPaymentRail | null; order_id?: string | null; }; export type ExecutionSucceededProperties = ExecutionTransactionSnapshotProperties & { fulfillment_time_ms: number | null; quote_id: string | null; }; export type ExecutionFailedProperties = ExecutionTransactionSnapshotProperties & ErrorProperties & { quote_id: string | null; }; export type DepositNotificationStatus = CheckoutStatus | 'delayed'; export type DepositNotificationProperties = ExecutionTransactionSnapshotProperties & { status: DepositNotificationStatus; }; export type DepositNotificationInteractedProperties = DepositNotificationProperties & { action: 'dismissed' | 'expanded'; ms_since_displayed: number; }; /** * Payload specific to {@link AnalyticsEvent.MODAL_OPENED}. Captures the * payment sources and checkout configuration available when the modal opens. */ export type ModalOpenedProperties = { custom_recipient: string | null; exchange_count: number; flow: AnalyticsFlow; primary_exchange: string | null; primary_wallet: string | null; source_asset: string | null; source_asset_ticker: string | null; source_chain: string | null; tab: PaymentMethodType; target_asset: string | null; target_asset_ticker: string | null; target_chain: string | null; wallet_count: number; }; /** Payload emitted when the user exits the current modal flow. */ export type ModalClosedProperties = { action: ModalClosedAction; completion_state: ModalCompletionState; flow: AnalyticsFlow; step: AnalyticsStep; }; /** Payload specific to {@link AnalyticsEvent.TAB_SWITCHED}. */ export type TabSwitchedProperties = { flow: AnalyticsFlow; from_tab: PaymentMethodType; /** 1-based switch ordinal for the current SourceChange visit. */ switch_count: number; tab: PaymentMethodType; }; export type StepViewedProperties = { flow: AnalyticsFlow; /** * Whether the user initiated a back navigation gesture. Note that we support * back navigation by step name, which falls back to pushing the step instead * if it's not already in history. Thus, `step_index` may still be incremented * even if `is_back_navigation` is true. */ is_back_navigation: boolean; prev_step: AnalyticsStep | null; step: AnalyticsStep; /** * 1-based index of the step being entered. When navigating backward, we attempt * to preserve the original index of the step when it was first entered. When * navigating forward, it is incremented by 1. */ step_index: number; }; /** Payload specific to {@link AnalyticsEvent.IFRAME_STEP_VIEWED}. */ export type IframeStepViewedProperties = { iframe_step: string; iframe_step_index: number; /** * True when `iframe_step` already appears in the current iframe-controller * navigation history. This is inferred from recurrence, not an observed Back * action, so a forward loop to a previously visited step may also be `true`. */ is_back_navigation: boolean; payment_method: string; payment_rail: 'swapped'; prev_iframe_step: string | null; step: AnalyticsStep; }; export type DepositTransferInteractionAction = 'address_copied' | 'chain_changed' | 'token_changed'; export type DepositTransferInteractedProperties = PaymentMethodProperties & { action: DepositTransferInteractionAction; deposit_address: string; est_price_impact: number | null; interaction_count: number; min_amount_usd: number; prev_source_asset: string | null; prev_source_asset_ticker: string | null; prev_source_chain: string | null; source_asset: string; source_asset_ticker: string; source_chain: string; target_asset: string; target_asset_ticker: string | null; target_chain: string; }; /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_METHOD_SELECTED}. */ export type WithdrawalMethodSelectedProperties = PaymentMethodProperties & { connection_status: ConnectionStatus | null; payment_rail: AnalyticsPaymentRail | null; }; /** Payload specific to {@link AnalyticsEvent.PERF_QUOTE}. */ export type PerfQuoteProperties = DepositAssetContextProperties & { execution_type: DirectExecutionType | null; /** 1-based quote request index within the checkout and quote flow. */ quote_attempt: number; /** 'base' measures time-to-first-quote; 'final' measures time-to-full-quote. */ quote_phase: 'base' | 'final'; source_amount: string | null; status: 'failed' | 'success'; step: AnalyticsStep; target_amount: string | null; total_ms: number; trade_type: QuoteMode; }; export type PerfStepReadyProperties = { [query_timing_ms: `query_timing_ms.${string}`]: number; is_first: boolean; payment_method: PaymentMethod | Lowercase | null; step: AnalyticsStep; total_ms: number; }; /** Payload specific to {@link AnalyticsEvent.PERF_IFRAME_READY}. */ export type PerfIframeReadyProperties = { /** First time this checkout's Swapped iframe reported ready. */ is_first: boolean; payment_method: string; payment_rail: 'swapped'; step: AnalyticsStep; /** * User-visible wait time (from step mount to ready). * May be ~0 if iframe was already fully preloaded. */ total_ms: number; }; export type WithdrawalTransferInteractionAction = 'address_autofilled' | 'address_changed' | 'amount_changed' | 'chain_changed' | 'max_button_clicked' | 'token_changed'; /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_TRANSFER_INTERACTED}. */ export type WithdrawalTransferInteractedProperties = PaymentMethodProperties & { action: WithdrawalTransferInteractionAction; balance_amount: string | null; interaction_count: number; prev_source_amount: string | null; prev_target_asset: string | null; prev_target_asset_ticker: string | null; prev_target_chain: string | null; recipient_address: string | null; source_amount: string | null; source_asset: string; source_asset_ticker: string; source_chain: string; target_asset: string | null; target_asset_ticker: string | null; target_chain: string | null; }; /** Route/quote fields shared by the withdrawal quote-lifecycle events. */ export type WithdrawalQuoteSnapshotProperties = PaymentMethodProperties & VisibleQuoteFeeProperties & { destination_address: string | null; /** Estimated fulfillment time in milliseconds. */ est_fulfillment_time_ms: number | null; execution_type: DirectExecutionType | null; sender_address: string | null; source_amount: string; source_chain: string; source_asset: string; source_asset_ticker: string | null; target_amount: string | null; target_chain: string; target_asset: string; target_asset_ticker: string | null; trade_type: QuoteMode; }; /** Quote snapshot plus quote-lifecycle metadata. */ export type WithdrawalQuoteContextProperties = WithdrawalQuoteSnapshotProperties & { num_quote_refreshes: number; quote_id: string | null; }; /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_QUOTE_DISPLAYED}. */ export type WithdrawalQuoteDisplayedProperties = WithdrawalQuoteContextProperties; /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_QUOTE_CONFIRMED}. */ export type WithdrawalQuoteConfirmedProperties = WithdrawalQuoteContextProperties; export type AnalyticsEventProperties = { [AnalyticsEvent.DEPOSIT_ASSET_SELECTED]: DepositAssetSelectedProperties; [AnalyticsEvent.DEPOSIT_AMOUNT_CONFIRMED]: DepositAmountConfirmedProperties; [AnalyticsEvent.DEPOSIT_FAILED]: ExecutionFailedProperties; [AnalyticsEvent.DEPOSIT_METHOD_SELECTED]: DepositMethodSelectedProperties; [AnalyticsEvent.DEPOSIT_NOTIFICATION_DISPLAYED]: DepositNotificationProperties; [AnalyticsEvent.DEPOSIT_NOTIFICATION_INTERACTED]: DepositNotificationInteractedProperties; [AnalyticsEvent.DEPOSIT_QUOTE_DISPLAYED]: DepositQuoteDisplayedProperties; [AnalyticsEvent.DEPOSIT_QUOTE_CONFIRMED]: DepositQuoteConfirmedProperties; [AnalyticsEvent.DEPOSIT_SUCCEEDED]: ExecutionSucceededProperties; [AnalyticsEvent.DEPOSIT_TRANSFER_INTERACTED]: DepositTransferInteractedProperties; [AnalyticsEvent.DEPOSIT_TRANSACTION_BREAKDOWN_CLICKED]: TransactionBreakdownClickedProperties; [AnalyticsEvent.DEPOSIT_TRANSACTION_SUBMITTED]: TransactionSubmittedProperties; [AnalyticsEvent.ERROR_SHOWN]: ErrorShownProperties; [AnalyticsEvent.IFRAME_STEP_VIEWED]: IframeStepViewedProperties; [AnalyticsEvent.MODAL_CLOSED]: ModalClosedProperties; [AnalyticsEvent.MODAL_OPENED]: ModalOpenedProperties; [AnalyticsEvent.PERF_IFRAME_READY]: PerfIframeReadyProperties; [AnalyticsEvent.PERF_QUOTE]: PerfQuoteProperties; [AnalyticsEvent.PERF_STEP_READY]: PerfStepReadyProperties; [AnalyticsEvent.STEP_VIEWED]: StepViewedProperties; [AnalyticsEvent.TAB_SWITCHED]: TabSwitchedProperties; [AnalyticsEvent.WITHDRAWAL_AMOUNT_CONFIRMED]: WithdrawalAmountConfirmedProperties; [AnalyticsEvent.WITHDRAWAL_FAILED]: ExecutionFailedProperties; [AnalyticsEvent.WITHDRAWAL_METHOD_SELECTED]: WithdrawalMethodSelectedProperties; [AnalyticsEvent.WITHDRAWAL_QUOTE_DISPLAYED]: WithdrawalQuoteDisplayedProperties; [AnalyticsEvent.WITHDRAWAL_QUOTE_CONFIRMED]: WithdrawalQuoteConfirmedProperties; [AnalyticsEvent.WITHDRAWAL_SUCCEEDED]: ExecutionSucceededProperties; [AnalyticsEvent.WITHDRAWAL_TRANSACTION_BREAKDOWN_CLICKED]: TransactionBreakdownClickedProperties; [AnalyticsEvent.WITHDRAWAL_TRANSFER_INTERACTED]: WithdrawalTransferInteractedProperties; [AnalyticsEvent.WITHDRAWAL_TRANSACTION_SUBMITTED]: TransactionSubmittedProperties; }; export type AnalyticsEventPayload = CommonProperties & AnalyticsEventProperties[T];