From 5d62348b47c377ecf0bf67c18b9ab21755c3a86c Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 31 Oct 2025 13:55:11 -0700 Subject: [PATCH 1/3] Add posthog global types --- src/types/posthog.d.ts | 8 ++++++++ src/util/tracking.ts | 3 --- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/types/posthog.d.ts diff --git a/src/types/posthog.d.ts b/src/types/posthog.d.ts new file mode 100644 index 00000000000..5b0320c3ef7 --- /dev/null +++ b/src/types/posthog.d.ts @@ -0,0 +1,8 @@ +import type { PostHog } from 'posthog-react-native' + +declare global { + // Expose the analytics instance on the global scope for app-wide use + // The PostHog instance is initialized at runtime + // See src/util/tracking.ts for initialization + var posthog: PostHog | undefined +} diff --git a/src/util/tracking.ts b/src/util/tracking.ts index 23efa3d584b..df6272d60e0 100644 --- a/src/util/tracking.ts +++ b/src/util/tracking.ts @@ -171,7 +171,6 @@ if (ENV.POSTHOG_INIT != null) { posthogAsync .then(client => { - // @ts-expect-error Attach PostHog instance to global for analytics access global.posthog = client }) .catch((e: unknown) => { @@ -408,10 +407,8 @@ async function logToPosthog( event: TrackingEventName, values: TrackingValues ): Promise { - // @ts-expect-error PostHog is attached to global at runtime if (global.posthog == null) return - // @ts-expect-error PostHog is attached to global at runtime global.posthog.capture(event, values) } From 90f3a9e60660e08e659bc81f7b94299bece7f252 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 31 Oct 2025 14:39:26 -0700 Subject: [PATCH 2/3] Fix lint errors in WalletListCreateRow --- eslint.config.mjs | 1 - src/components/themed/WalletListCreateRow.tsx | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 0d3d1bad0ba..b0060b39c8c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -375,7 +375,6 @@ export default [ 'src/components/themed/TransactionListTop.tsx', 'src/components/themed/VectorIcon.tsx', 'src/components/themed/WalletList.tsx', - 'src/components/themed/WalletListCreateRow.tsx', 'src/components/themed/WalletListErrorRow.tsx', 'src/components/themed/WalletListHeader.tsx', diff --git a/src/components/themed/WalletListCreateRow.tsx b/src/components/themed/WalletListCreateRow.tsx index d85a90c0fd2..c5fe8891434 100644 --- a/src/components/themed/WalletListCreateRow.tsx +++ b/src/components/themed/WalletListCreateRow.tsx @@ -35,7 +35,7 @@ export interface WalletListCreateRowProps { export const WalletListCreateRowComponent = ( props: WalletListCreateRowProps -) => { +): React.ReactElement => { const { createItem, createWalletId, @@ -88,7 +88,7 @@ export const WalletListCreateRowComponent = ( if (walletType != null) { await dispatch(createAndSelectWallet(pluginId, keyOptions)) .then(handleRes) - .catch(err => { + .catch((err: unknown) => { showError(err) }) .finally(() => (pressMutexRef.current = false)) @@ -104,13 +104,15 @@ export const WalletListCreateRowComponent = ( }) ) .then(handleRes) - .catch(err => { + .catch((err: unknown) => { showError(err) }) .finally(() => (pressMutexRef.current = false)) } else { await Airship.show(bridge => { - const renderRow = (wallet: EdgeCurrencyWallet) => ( + const renderRow = ( + wallet: EdgeCurrencyWallet + ): React.ReactElement => ( ) }) - .catch(err => { + .catch((err: unknown) => { showError(err) }) .finally(() => (pressMutexRef.current = false)) From 957d4ced319cbf627ea436b5a4e03520a1ecf0ed Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 31 Oct 2025 14:39:46 -0700 Subject: [PATCH 3/3] Add missing dispatch invocations for logEvent --- CHANGELOG.md | 1 + src/actions/AccountReferralActions.ts | 6 +++--- src/components/scenes/RampCreateScene.tsx | 6 ++++-- src/components/themed/WalletListCreateRow.tsx | 4 ++-- src/plugins/gui/amountQuotePlugin.ts | 14 ++++++++++---- src/plugins/gui/fiatPlugin.tsx | 3 ++- src/plugins/gui/fiatPluginTypes.ts | 4 +++- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05895595d0..625bd1dde8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased (develop) +- fixed: Fixed broken `logEvent` tracking calls by adding the needed `dispatch`. - removed: Remove change quote tracking. ## 4.38.0 (staging) diff --git a/src/actions/AccountReferralActions.ts b/src/actions/AccountReferralActions.ts index 8d1bada343f..70ff9c5511c 100644 --- a/src/actions/AccountReferralActions.ts +++ b/src/actions/AccountReferralActions.ts @@ -123,13 +123,13 @@ function createAccountReferral(): ThunkAction> { referral.accountAppleAdsAttribution = isFirstOpenEmpty ? await getAppleAdsAttribution() : firstOpenAttrib - logEvent('AAA_Success') + dispatch(logEvent('AAA_Success')) } else { referral.accountAppleAdsAttribution = await getAppleAdsAttribution() if (referral.accountAppleAdsAttribution == null) { - logEvent('AAA_Failed') + dispatch(logEvent('AAA_Failed')) } else { - logEvent('AAA_Success') + dispatch(logEvent('AAA_Success')) } } } catch (e) {} diff --git a/src/components/scenes/RampCreateScene.tsx b/src/components/scenes/RampCreateScene.tsx index 524a01fb8b3..794e0d2a3d2 100644 --- a/src/components/scenes/RampCreateScene.tsx +++ b/src/components/scenes/RampCreateScene.tsx @@ -525,7 +525,7 @@ export const RampCreateScene: React.FC = (props: Props) => { // Log the quote event only when the scene is focused useFocusEffect(() => { - logEvent(direction === 'buy' ? 'Buy_Quote' : 'Sell_Quote') + dispatch(logEvent(direction === 'buy' ? 'Buy_Quote' : 'Sell_Quote')) }) // @@ -619,7 +619,9 @@ export const RampCreateScene: React.FC = (props: Props) => { } } - logEvent(direction === 'buy' ? 'Buy_Quote_Next' : 'Sell_Quote_Next') + dispatch( + logEvent(direction === 'buy' ? 'Buy_Quote_Next' : 'Sell_Quote_Next') + ) navigation.navigate('rampSelectOption', { rampQuoteRequest diff --git a/src/components/themed/WalletListCreateRow.tsx b/src/components/themed/WalletListCreateRow.tsx index c5fe8891434..35d8f8cc5a4 100644 --- a/src/components/themed/WalletListCreateRow.tsx +++ b/src/components/themed/WalletListCreateRow.tsx @@ -240,12 +240,12 @@ function createAndSelectToken({ ) await wallet.changeEnabledTokenIds([...wallet.enabledTokenIds, tokenId]) - if (trackingEventSuccess != null) logEvent(trackingEventSuccess) + if (trackingEventSuccess != null) dispatch(logEvent(trackingEventSuccess)) return wallet } catch (error: any) { showError(error) if (trackingEventFailed != null) - logEvent(trackingEventFailed, { error: String(error) }) + dispatch(logEvent(trackingEventFailed, { error: String(error) })) } } } diff --git a/src/plugins/gui/amountQuotePlugin.ts b/src/plugins/gui/amountQuotePlugin.ts index 9aa5a5df4a1..ab5bdd61603 100644 --- a/src/plugins/gui/amountQuotePlugin.ts +++ b/src/plugins/gui/amountQuotePlugin.ts @@ -13,7 +13,6 @@ import { } from '../../util/CurrencyInfoHelpers' import { getHistoricalFiatRate } from '../../util/exchangeRates' import { infoServerData } from '../../util/network' -import { logEvent } from '../../util/tracking' import { DECIMAL_PRECISION, fuzzyTimeout, @@ -134,7 +133,14 @@ async function getInitialFiatValue( export const amountQuoteFiatPlugin: FiatPluginFactory = async ( params: FiatPluginFactoryArgs ) => { - const { account, guiPlugin, longPress = false, pluginUtils, showUi } = params + const { + account, + guiPlugin, + longPress = false, + pluginUtils, + showUi, + onLogEvent + } = params const { pluginId } = guiPlugin const isLightAccount = account.username == null @@ -352,7 +358,7 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async ( const isBuy = direction === 'buy' const disableInput = requireCrypto ? 1 : requireFiat ? 2 : undefined - logEvent(isBuy ? 'Buy_Quote' : 'Sell_Quote') + onLogEvent(isBuy ? 'Buy_Quote' : 'Sell_Quote') const startingFiatAmount = isLightAccount ? DEFAULT_FIAT_AMOUNT_LIGHT_ACCOUNT @@ -776,7 +782,7 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async ( } } - logEvent(isBuy ? 'Buy_Quote_Next' : 'Sell_Quote_Next') + onLogEvent(isBuy ? 'Buy_Quote_Next' : 'Sell_Quote_Next') await bestQuote.approveQuote({ showUi, coreWallet }) } } diff --git a/src/plugins/gui/fiatPlugin.tsx b/src/plugins/gui/fiatPlugin.tsx index f1d68f5fd76..3f86dfca5a2 100644 --- a/src/plugins/gui/fiatPlugin.tsx +++ b/src/plugins/gui/fiatPlugin.tsx @@ -461,7 +461,8 @@ export const executePlugin = async (params: { longPress, guiPlugin, pluginUtils, - showUi + showUi, + onLogEvent }) if (plugin == null) { throw new Error(`pluginId ${pluginId} not found`) diff --git a/src/plugins/gui/fiatPluginTypes.ts b/src/plugins/gui/fiatPluginTypes.ts index 45f59ced386..47a33079648 100644 --- a/src/plugins/gui/fiatPluginTypes.ts +++ b/src/plugins/gui/fiatPluginTypes.ts @@ -29,7 +29,8 @@ import type { import type { BuyConversionValues, SellConversionValues, - TrackingEventName + TrackingEventName, + TrackingValues } from '../../util/tracking' import type { FiatPluginAddressFormParams } from './scenes/AddressFormScene' import type { FiatPluginOpenWebViewParams } from './scenes/FiatPluginWebView' @@ -220,6 +221,7 @@ export interface FiatPluginFactoryArgs { guiPlugin: GuiPlugin showUi: FiatPluginUi pluginUtils: FiatPluginUtils + onLogEvent: (event: TrackingEventName, values?: TrackingValues) => void } export interface FiatPluginRegionCode {