Skip to content

Add analytics to Buy/Sell flow #12415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged

Add analytics to Buy/Sell flow #12415

merged 3 commits into from
Jun 27, 2025

Conversation

faridsalau
Copy link
Contributor

@faridsalau faridsalau commented Jun 25, 2025

Description

This PR introduces new analytics tracking for the buy and sell flows within the application. It leverages a new useBuySellAnalytics hook to provide consistent and type-safe event tracking for various stages of the swap process.

Changes:

  • New Analytics Hooks:

    • useAnalytics.ts: A core analytics hook providing a consistent interface for tracking events.
    • useBuySellAnalytics.ts: A specialized hook for buy-sell swap flows, with pre-configured methods for events like trackSwapRequested, trackSwapConfirmed, trackSwapSuccess, trackSwapFailure, and trackAddFundsClicked.
  • Analytics Event Definitions:

    • Added new Name enums and corresponding types (BuySellSwapEventFields, BuySellSwapRequested, BuySellSwapConfirmed, BuySellSwapSuccess, BuySellSwapFailure, BuySellAddFundsClicked) in packages/common/src/models/Analytics.ts to support the new buy/sell analytics events.
  • Integration into Buy/Sell Flow:

    • Updated packages/mobile/src/screens/buy-sell-screen/BuySellFlow.tsx to utilize the useBuySellAnalytics hook for tracking trackSwapRequested and trackAddFundsClicked events.
    • Removed direct make and track calls in BuySellFlow.tsx in favor of the new specialized hook.
  • Store Updates:

    • Modified packages/common/src/store/ui/buy-sell/types.ts to include ConfirmationScreenData and exchangeRate in SuccessDisplayData, and signature in SwapResult. Also added getSwapTokens utility.
    • Adjusted packages/common/src/store/ui/buy-sell/useBuySellSwap.ts to pass signature in trackSwapSuccess.
    • Updated packages/common/src/store/ui/buy-sell/useSwapDisplayData.ts and packages/common/src/store/ui/buy-sell/useTokenSwapForm.ts to handle exchangeRate more consistently.

These changes ensure that all critical actions within the buy and sell flows are properly instrumented for analytics, providing better insights into user behavior.

Copy link

changeset-bot bot commented Jun 25, 2025

⚠️ No Changeset found

Latest commit: a50eddd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@faridsalau faridsalau marked this pull request as ready for review June 25, 2025 21:27
@faridsalau faridsalau changed the title Add analytics Add analytics to Buy/Sell flow Jun 25, 2025
import { useAppContext } from '~/context/appContext'
import { AnalyticsEvent, AllTrackingEvents } from '~/models/Analytics'

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk if we need all these AI comments tbh

@@ -0,0 +1,56 @@
import { useCallback } from 'react'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait do we really need this hook? what does this give us that the existing infrastructure doesn't?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, to be able to use it in common?

@@ -82,7 +82,7 @@ export const useBuySellSwap = (props: UseBuySellSwapProps) => {
retryTimeoutRef.current = setTimeout(() => {
invalidateBalances()
performSwap()
}, RETRY_DELAY)
}, RETRY_DELAY) as unknown as NodeJS.Timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea typecheck thing

@faridsalau faridsalau merged commit fe71b33 into main Jun 27, 2025
9 of 10 checks passed
@faridsalau faridsalau deleted the fs-buy-sell-analytics branch June 27, 2025 09:14
audius-infra pushed a commit that referenced this pull request Jun 28, 2025
[f1cd30c] [PE-6452] Refactor web lineup tiles (#12424) Dylan Jeffers
[b83ee65] Prime search results to improve autocomplete performance (#12425) Isaac Solo
[c12b5d7] Add rich notifications to enable image urls (#12428) Farid Salau
[fe71b33] Add analytics to Buy/Sell flow (#12415) Farid Salau
[c006e1f] Move protocol dashboard to cloudflare deployment (#12420) Ray Jacobson
[d1b2ba1] [HOTFIX] Fix manager mode not letting you swap from managee (#12423) JD Francis
[1e34849] [PE-6454] Fix purchases after BN.js migration (#12426) Reed
[6b465b8] Use prime functions for entity updates (#12421) Dylan Jeffers
[c428cd2] Drop search test (#12422) Dylan Jeffers
[31f5416] Fix another incorrect instance of waitForValue (#12419) JD Francis
[79e3551] Fix purchase flow stuck due to waitForValue (#12418) JD Francis
[1717738] [QA-2184] Fix double $ signs in purchase flow (#12417) Reed
[ca3a6a2] Fix publish playlist button on missing track count (#12413) Isaac Solo
[e6d86ba] Fix AudioHoverCard balance (#12416) Reed
[3b2fecf] Update AudioBreakdownDrawer to use balance hooks and harmony (#12414) Reed
[35a55b1] [PE-6450] Fix mobile audio balance formatting (#12412) Reed
[6bc66da] Fix search lineup issues (#12411) JD Francis
[bf7fa37] [QA-2168] Fix mobile-web prev/next button color (#12408) Dylan Jeffers
[b9e1b25] [PE-6448] Fix mobile track tile favorites and library loading (#12409) Dylan Jeffers
[d9c33bf] Fix infinite loop in mobile DMs (#12410) JD Francis
[3e940b9] [PE-6418] Fix artist all hidden tracks (#12405) Dylan Jeffers
[d7ffb72] Fix mobile library track tab filter display (#12402) Dylan Jeffers
[11cefe8] [PE-6431] Fix extra user/handle API calls (#12406) JD Francis
[2ef0a61] Adjust content padding and center align text (#12403) Isaac Solo
[ec230ca] [PE-6433] Fix signed out search (#12400) Dylan Jeffers
[3da884f] [PE-6441] Fix create new collection (#12404) Dylan Jeffers
[e5405c6] [PE-6443] Fix collection tiles not playing in lineups (#12398) JD Francis
[09a7716] [PE-6436] Fix mobile withdraw flow scrolling and validation (#12401) Reed
[b351681] Add reactotron for RN network debugging (#12399) Farid Salau
[7898ff7] Add retries on swaps (#12397) Farid Salau
[8beb206] Fix header snapping and improve content scrolling (#12396) Isaac Solo
[ea8b873] [PE-6427] Fix play bar duration (#12389) Dylan Jeffers
[7de9a49] [QA-2160 PE-6438] Fix Android icon colors (#12390) Dylan Jeffers
[2e5d6e5] [PE-6432] Reduce mobile web explore page tiles (#12393) Dylan Jeffers
[ed89aa8] [PE-6435] Fix selectable pill isSelected color (#12392) Dylan Jeffers
[c30350e] [QA-2167] Hide empty track page lineup for artists with one track (#12395) KJ
[590ccea] [QA-1625] Contain scroll in playlist tiles (#12394) KJ
[cc42ce5] [PE-6428] Fix_confetti_final_final_final_v2 (#12387) JD Francis
[8ef4ca4] [PE-6419|PE-6434] Fix flash of sign up on mobile apps due to default account status (#12384) JD Francis
[d5ba7b9] [PE-6383] Fix ATA of ATA bug in withdraw flow (#12382) Reed
[1026ce1] Remove BN.js from web/mobile/common/embed/fixed-decimal (#12368) Reed
[a539209] Optimize search and explore performance + animation (#12375) Isaac Solo
[443937c] [PE-6403] Fix mobile library radio buttons not working (#12349) JD Francis
[799cb55] [QA-2161] Fix mobile favorited album/playlist search (#12374) Dylan Jeffers
[d9bb313] [QA-2165] Fix profile nav item navigation (#12376) Dylan Jeffers
[bba94bd] [QA-2166] Fix broken mobile playback (#12377) Dylan Jeffers
[86c5fbf] Refactor TrendingPageProvider to funcitonal component (#12378) Farid Salau
[8b7db22] [QA-1985] Remove multiselect prop to fix upload tag delete on click functionality (#12379) KJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants