-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: STAKE-827: track additional pooled staking events (#12290)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Adds additional event tracking for pooled-staking tooltips and currency switching. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Jira Ticket: [STAKE-827: Track more events in Mixpanel](https://consensyssoftware.atlassian.net/browse/STAKE-827) ## **Manual testing steps** **note: there's an ongoing issues with tracking events on local dev. Results may vary.** Prerequisite: Add `export MM_POOLED_STAKING_UI_ENABLED=true` to your local `.js.env` file Testing Currency Switch Events 1. Click on Ethereum in assets list 2. Click "Stake", "Stake More", or "Unstake" buttons to navigate to the input screen 3. Switch the currency between native and fiat near the top of the screen Testing Tooltip Events 1. Click on Ethereum in assets list 2. Click on available tooltip icons: - Annual rate in the "Your earnings" section within ETH details page - Learn more tooltip on the staking input screen - Various tooltips on the stake and unstake confirmation views ## **Screenshots/Recordings** N/A <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
13 changed files
with
213 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/components/UI/Stake/utils/metaMetrics/tooltipMetaMetricsUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MetricsEventBuilder } from '../../../../../core/Analytics/MetricsEventBuilder'; | ||
import { MetaMetricsEvents } from '../../../../hooks/useMetrics'; | ||
|
||
export const getTooltipMetricProperties = ( | ||
location: string, | ||
tooltipName: string, | ||
) => ({ | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location, | ||
tooltip_name: tooltipName, | ||
}); | ||
|
||
export const createTooltipOpenedEvent = ( | ||
location: string, | ||
tooltipName: string, | ||
) => { | ||
const createEventBuilder = MetricsEventBuilder.createEventBuilder; | ||
|
||
return createEventBuilder(MetaMetricsEvents.TOOLTIP_OPENED) | ||
.addProperties(getTooltipMetricProperties(location, tooltipName)) | ||
.build(); | ||
}; |
56 changes: 56 additions & 0 deletions
56
app/components/UI/Stake/utils/metaMetrics/withMetaMetrics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
IMetaMetricsEvent, | ||
JsonMap, | ||
} from '../../../../../core/Analytics/MetaMetrics.types'; | ||
import { MetricsEventBuilder } from '../../../../../core/Analytics/MetricsEventBuilder'; | ||
import { MetaMetrics } from '../../../../../core/Analytics'; | ||
|
||
interface WithMetaMetricsEvent { | ||
event: IMetaMetricsEvent; | ||
properties?: JsonMap; | ||
} | ||
|
||
const createEventBuilder = MetricsEventBuilder.createEventBuilder; | ||
|
||
const shouldAddProperties = (properties?: JsonMap): properties is JsonMap => { | ||
if (!properties) return false; | ||
return Object.keys(properties).length > 0; | ||
}; | ||
|
||
const buildEvent = (e: WithMetaMetricsEvent) => { | ||
const eventBuilder = createEventBuilder(e.event); | ||
|
||
if (shouldAddProperties(e?.properties)) { | ||
eventBuilder.addProperties(e.properties); | ||
} | ||
|
||
return eventBuilder.build(); | ||
}; | ||
|
||
export const withMetaMetrics = <T extends (...args: unknown[]) => unknown>( | ||
func: T, | ||
events: WithMetaMetricsEvent | WithMetaMetricsEvent[], | ||
) => { | ||
if (!Array.isArray(events)) { | ||
events = [events]; | ||
} | ||
|
||
const builtEvents = events.map((event) => buildEvent(event)); | ||
|
||
return (...args: Parameters<T>): ReturnType<T> | Promise<ReturnType<T>> => { | ||
const result = func(...args); | ||
|
||
if (result instanceof Promise) { | ||
return result.then((res) => { | ||
builtEvents.forEach((event) => | ||
MetaMetrics.getInstance().trackEvent(event), | ||
); | ||
return res; | ||
}) as Promise<ReturnType<T>>; | ||
} | ||
|
||
builtEvents.forEach((event) => MetaMetrics.getInstance().trackEvent(event)); | ||
|
||
return result as ReturnType<T>; | ||
}; | ||
}; |
Oops, something went wrong.