Skip to content

Commit 39363b3

Browse files
authored
Merge pull request #5828 from EdgeApp/sam/posthog-capture-event-fixes
Sam/posthog capture event fixes
2 parents 1ff72e2 + 957d4ce commit 39363b3

File tree

10 files changed

+40
-22
lines changed

10 files changed

+40
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased (develop)
44

5+
- fixed: Fixed broken `logEvent` tracking calls by adding the needed `dispatch`.
56
- removed: Remove change quote tracking.
67

78
## 4.38.0 (staging)

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ export default [
375375
'src/components/themed/TransactionListTop.tsx',
376376
'src/components/themed/VectorIcon.tsx',
377377
'src/components/themed/WalletList.tsx',
378-
'src/components/themed/WalletListCreateRow.tsx',
379378

380379
'src/components/themed/WalletListErrorRow.tsx',
381380
'src/components/themed/WalletListHeader.tsx',

src/actions/AccountReferralActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ function createAccountReferral(): ThunkAction<Promise<void>> {
123123
referral.accountAppleAdsAttribution = isFirstOpenEmpty
124124
? await getAppleAdsAttribution()
125125
: firstOpenAttrib
126-
logEvent('AAA_Success')
126+
dispatch(logEvent('AAA_Success'))
127127
} else {
128128
referral.accountAppleAdsAttribution = await getAppleAdsAttribution()
129129
if (referral.accountAppleAdsAttribution == null) {
130-
logEvent('AAA_Failed')
130+
dispatch(logEvent('AAA_Failed'))
131131
} else {
132-
logEvent('AAA_Success')
132+
dispatch(logEvent('AAA_Success'))
133133
}
134134
}
135135
} catch (e) {}

src/components/scenes/RampCreateScene.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
525525

526526
// Log the quote event only when the scene is focused
527527
useFocusEffect(() => {
528-
logEvent(direction === 'buy' ? 'Buy_Quote' : 'Sell_Quote')
528+
dispatch(logEvent(direction === 'buy' ? 'Buy_Quote' : 'Sell_Quote'))
529529
})
530530

531531
//
@@ -619,7 +619,9 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
619619
}
620620
}
621621

622-
logEvent(direction === 'buy' ? 'Buy_Quote_Next' : 'Sell_Quote_Next')
622+
dispatch(
623+
logEvent(direction === 'buy' ? 'Buy_Quote_Next' : 'Sell_Quote_Next')
624+
)
623625

624626
navigation.navigate('rampSelectOption', {
625627
rampQuoteRequest

src/components/themed/WalletListCreateRow.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface WalletListCreateRowProps {
3535

3636
export const WalletListCreateRowComponent = (
3737
props: WalletListCreateRowProps
38-
) => {
38+
): React.ReactElement => {
3939
const {
4040
createItem,
4141
createWalletId,
@@ -88,7 +88,7 @@ export const WalletListCreateRowComponent = (
8888
if (walletType != null) {
8989
await dispatch(createAndSelectWallet(pluginId, keyOptions))
9090
.then(handleRes)
91-
.catch(err => {
91+
.catch((err: unknown) => {
9292
showError(err)
9393
})
9494
.finally(() => (pressMutexRef.current = false))
@@ -104,13 +104,15 @@ export const WalletListCreateRowComponent = (
104104
})
105105
)
106106
.then(handleRes)
107-
.catch(err => {
107+
.catch((err: unknown) => {
108108
showError(err)
109109
})
110110
.finally(() => (pressMutexRef.current = false))
111111
} else {
112112
await Airship.show(bridge => {
113-
const renderRow = (wallet: EdgeCurrencyWallet) => (
113+
const renderRow = (
114+
wallet: EdgeCurrencyWallet
115+
): React.ReactElement => (
114116
<WalletListCurrencyRow
115117
tokenId={null}
116118
wallet={wallet}
@@ -149,7 +151,7 @@ export const WalletListCreateRowComponent = (
149151
/>
150152
)
151153
})
152-
.catch(err => {
154+
.catch((err: unknown) => {
153155
showError(err)
154156
})
155157
.finally(() => (pressMutexRef.current = false))
@@ -238,12 +240,12 @@ function createAndSelectToken({
238240
)
239241

240242
await wallet.changeEnabledTokenIds([...wallet.enabledTokenIds, tokenId])
241-
if (trackingEventSuccess != null) logEvent(trackingEventSuccess)
243+
if (trackingEventSuccess != null) dispatch(logEvent(trackingEventSuccess))
242244
return wallet
243245
} catch (error: any) {
244246
showError(error)
245247
if (trackingEventFailed != null)
246-
logEvent(trackingEventFailed, { error: String(error) })
248+
dispatch(logEvent(trackingEventFailed, { error: String(error) }))
247249
}
248250
}
249251
}

src/plugins/gui/amountQuotePlugin.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from '../../util/CurrencyInfoHelpers'
1414
import { getHistoricalFiatRate } from '../../util/exchangeRates'
1515
import { infoServerData } from '../../util/network'
16-
import { logEvent } from '../../util/tracking'
1716
import {
1817
DECIMAL_PRECISION,
1918
fuzzyTimeout,
@@ -134,7 +133,14 @@ async function getInitialFiatValue(
134133
export const amountQuoteFiatPlugin: FiatPluginFactory = async (
135134
params: FiatPluginFactoryArgs
136135
) => {
137-
const { account, guiPlugin, longPress = false, pluginUtils, showUi } = params
136+
const {
137+
account,
138+
guiPlugin,
139+
longPress = false,
140+
pluginUtils,
141+
showUi,
142+
onLogEvent
143+
} = params
138144
const { pluginId } = guiPlugin
139145
const isLightAccount = account.username == null
140146

@@ -352,7 +358,7 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (
352358
const isBuy = direction === 'buy'
353359
const disableInput = requireCrypto ? 1 : requireFiat ? 2 : undefined
354360

355-
logEvent(isBuy ? 'Buy_Quote' : 'Sell_Quote')
361+
onLogEvent(isBuy ? 'Buy_Quote' : 'Sell_Quote')
356362

357363
const startingFiatAmount = isLightAccount
358364
? DEFAULT_FIAT_AMOUNT_LIGHT_ACCOUNT
@@ -776,7 +782,7 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (
776782
}
777783
}
778784

779-
logEvent(isBuy ? 'Buy_Quote_Next' : 'Sell_Quote_Next')
785+
onLogEvent(isBuy ? 'Buy_Quote_Next' : 'Sell_Quote_Next')
780786
await bestQuote.approveQuote({ showUi, coreWallet })
781787
}
782788
}

src/plugins/gui/fiatPlugin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ export const executePlugin = async (params: {
461461
longPress,
462462
guiPlugin,
463463
pluginUtils,
464-
showUi
464+
showUi,
465+
onLogEvent
465466
})
466467
if (plugin == null) {
467468
throw new Error(`pluginId ${pluginId} not found`)

src/plugins/gui/fiatPluginTypes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import type {
2929
import type {
3030
BuyConversionValues,
3131
SellConversionValues,
32-
TrackingEventName
32+
TrackingEventName,
33+
TrackingValues
3334
} from '../../util/tracking'
3435
import type { FiatPluginAddressFormParams } from './scenes/AddressFormScene'
3536
import type { FiatPluginOpenWebViewParams } from './scenes/FiatPluginWebView'
@@ -220,6 +221,7 @@ export interface FiatPluginFactoryArgs {
220221
guiPlugin: GuiPlugin
221222
showUi: FiatPluginUi
222223
pluginUtils: FiatPluginUtils
224+
onLogEvent: (event: TrackingEventName, values?: TrackingValues) => void
223225
}
224226

225227
export interface FiatPluginRegionCode {

src/types/posthog.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { PostHog } from 'posthog-react-native'
2+
3+
declare global {
4+
// Expose the analytics instance on the global scope for app-wide use
5+
// The PostHog instance is initialized at runtime
6+
// See src/util/tracking.ts for initialization
7+
var posthog: PostHog | undefined
8+
}

src/util/tracking.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ if (ENV.POSTHOG_INIT != null) {
171171

172172
posthogAsync
173173
.then(client => {
174-
// @ts-expect-error Attach PostHog instance to global for analytics access
175174
global.posthog = client
176175
})
177176
.catch((e: unknown) => {
@@ -408,10 +407,8 @@ async function logToPosthog(
408407
event: TrackingEventName,
409408
values: TrackingValues
410409
): Promise<void> {
411-
// @ts-expect-error PostHog is attached to global at runtime
412410
if (global.posthog == null) return
413411

414-
// @ts-expect-error PostHog is attached to global at runtime
415412
global.posthog.capture(event, values)
416413
}
417414

0 commit comments

Comments
 (0)