Skip to content
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

feat: Add simulation metrics to "Transaction Submitted" and "Transaction Finalized" events #28240

Merged

Conversation

digiwand
Copy link
Contributor

@digiwand digiwand commented Nov 1, 2024

Description

This PR adds simulation metrics to the Transaction Submitted and Transaction Finalized events.

Please refer to Solution B) below for details.


The challenge here is that there are two separate transaction fragment buckets: transaction-added-<id> and transaction-submitted-<id>.
transaction-added-<id> fragments are associated with the events:

  • Transaction Added
  • Transaction Approved
  • Transaction Rejected

transaction-submitted-<id> fragments are associated with the events:

  • Transaction Submitted
  • Transaction Finalized

Simulation metrics were added to "Transaction Approved" and "Transaction Rejected" events using updateEventFragment. When they were added here through the useTransactionEventFragment hook, the transaction-submitted-<id> fragment had not yet been created. The transaction-submitted-<id> fragment is created after a user clicks the Confirm button on a transaction which invokes metrics#handleTransactionSubmitted and calls createTransactionEventFragment

To solve this, I proposed two solutions (TLDR; went with Solution B):

Solution A)

  • Create a single transaction fragment ID to handle all related transaction events. Here, the fragment would specify the props:
initialEvent: "Transaction Added"
successEvent:"Transaction Finalized"
failureEvent: "Transaction Rejected"
  • Add new method to MetaMetricsController to call trackEvent with specified eventName utilizing fragment props. This would support calling "Transaction Approved" and "Transaction Submitted" ad-hoc style.

Solution B)

  • Allow a premature fragment to exist for transaction-submitted-<id> fragment. Prior to this PR fragments only exist once they are created.
  • From useTransactionEventFragment hook
    • Adds a premature transaction-submitted-<id> fragment
    • Calls "updateEventFragment(transaction-submitted-${transactionId}, params)" to store simulation metric props
  • When handleTransactionSubmitted event is invoked, creating the fragment now merges the premature fragment with the newly created fragment
  • When a premature fragment is found as an abandoned fragment, we delete it from the store

Solution C)

  • store unlinked props in new store state: fragmentsUnlinkedProps on updateEventFragment
  • fragmentsUnlinkedProps can be applied to newly created fragments on createEventFragment
  • deleted abandoned fragmentsUnlinkedProps would need more investigation

I went with solution B due to time constraints.

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3507

Manual testing steps

  1. Turn on "Participate in MetaMetrics" setting
  2. Confirm or Reject a Send transaction
  3. Observe simulation props are added to Transaction Submitted and Transaction Finalized events

Screenshots/Recordings

no UI/UX changes

Before

After

Pre-merge author checklist

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.

@digiwand digiwand requested review from a team as code owners November 1, 2024 13:08
Copy link
Contributor

github-actions bot commented Nov 1, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@github-actions github-actions bot added the team-confirmations Push issues to confirmations team label Nov 1, 2024
case TransactionMetaMetricsEvent.finalized:
transactionMetricsRequest.updateEventFragment(uniqueId, {
properties: payload.properties,
sensitiveProperties: payload.sensitiveProperties,
});
break;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

minor cleanup since they were calling the same logic

app/scripts/controllers/metametrics.ts Outdated Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Outdated Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Outdated Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Outdated Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Outdated Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Show resolved Hide resolved
app/scripts/controllers/metametrics.ts Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [54d3cb3]
Page Load Metrics (1763 ± 53 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33820111687329158
domContentLoaded15841940173310551
load15942013176311153
domInteractive17231635828
backgroundConnect974292110
firstReactRender47298965124
getState55415147
initialActions01000
loadScripts1084141112569646
setupStore1094302512
uiStartup17472557197217986
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 513 Bytes (0.01%)
  • ui: 58 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [b279b9c]
Page Load Metrics (1841 ± 103 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint160125811846211101
domContentLoaded158325541820211101
load159425771841214103
domInteractive17165593617
backgroundConnect9105252311
firstReactRender47286935124
getState54912126
initialActions01000
loadScripts11221886133215675
setupStore1172352713
uiStartup179527112053219105
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 503 Bytes (0.01%)
  • ui: 58 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [0f4c0d9]
Page Load Metrics (1982 ± 106 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint37526141885404194
domContentLoaded164726061950217104
load165526141982221106
domInteractive30126552311
backgroundConnect971292010
firstReactRender49148982512
getState55613147
initialActions01000
loadScripts12402050146718589
setupStore1174302411
uiStartup184628472191239115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 502 Bytes (0.01%)
  • ui: 58 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [671cadd]
Page Load Metrics (1936 ± 90 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint26624011768522250
domContentLoaded16862325190218689
load16952401193618890
domInteractive19197533617
backgroundConnect979342211
firstReactRender51129962512
getState56416189
initialActions01000
loadScripts12151732140615072
setupStore1166332210
uiStartup188525872151212102
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 502 Bytes (0.01%)
  • ui: 58 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Member

@matthewwalsh0 matthewwalsh0 left a comment

Choose a reason for hiding this comment

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

Great fix, though eager for us to come back to this soon to reduce coupling.

@digiwand
Copy link
Contributor Author

digiwand commented Nov 5, 2024

Thanks for the reviews and can do @matthewwalsh0!

dedupe related comment: #28240 (comment)

@digiwand digiwand added this pull request to the merge queue Nov 5, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [9bebfe6]
Page Load Metrics (2012 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40422711943379182
domContentLoaded16862212197113263
load16902267201214770
domInteractive19290555727
backgroundConnect799412914
firstReactRender613021205527
getState46219178
initialActions01000
loadScripts12301608145812761
setupStore1096432914
uiStartup19242725229817986
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 502 Bytes (0.01%)
  • ui: 58 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Merged via the queue into develop with commit 82c1910 Nov 5, 2024
76 checks passed
@digiwand digiwand deleted the add-tx-simulation-metrics-for-submitted-and-finalized branch November 5, 2024 17:29
@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2024
@metamaskbot metamaskbot added the release-12.8.0 Issue or pull request that will be included in release 12.8.0 label Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.8.0 Issue or pull request that will be included in release 12.8.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants