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 metrics for alerts (transactions redesign) #26121

Merged
merged 23 commits into from
Aug 12, 2024

Conversation

vinistevam
Copy link
Contributor

@vinistevam vinistevam commented Jul 25, 2024

Description

Recently the Alert System was introduced to redesigned confirmations with this the alerts for those confirmations were migrated to use the new Alert System. This PR introduces infrastructure to track metrics for alerts in the redesigned confirmation system. It ensures that alert metrics are captured and included in the necessary places for tracking.

The use of a context to manage shared state for alert metrics within the confirmation flow. The context approach was chosen because it allows us to maintain a single instance of the shared state per confirmation. This is crucial for ensuring that clicks on different inline alerts and actions are persisted and aggregated into a unified set of properties. These aggregated properties are then added to the transaction event, providing a comprehensive view of user interactions within the confirmation process.

Open in GitHub Codespaces

Related issues

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

Manual testing steps

  1. Go to the test dapp
  2. in the session PPOM - Malicious Transactions and Signatures > mint ERC20

Screenshots/Recordings

confirm.webm
reject.webm

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.

Copy link
Contributor

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.

@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Jul 25, 2024
@vinistevam vinistevam force-pushed the feat/redesign-transaction-metrics-alerts branch from ab98c8d to 051fd66 Compare July 25, 2024 13:57
@vinistevam vinistevam force-pushed the feat/redesign-transaction-metrics-alerts branch from 6e49030 to c948f7f Compare July 26, 2024 09:17
@metamaskbot
Copy link
Collaborator

Builds ready [c948f7f]
Page Load Metrics (146 ± 169 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint69149972311
domContentLoaded96726168
load401678146352169
domInteractive96726168
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 7.31 KiB (0.10%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [2609816]
Page Load Metrics (65 ± 6 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint5911892178
domContentLoaded95226146
load398565136
domInteractive95226146
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 7.32 KiB (0.10%)
  • common: 0 Bytes (0.00%)

@vinistevam vinistevam changed the title feat: add metrics for alerts feat: Add metrics for alerts (transactions redesign) Jul 26, 2024
@vinistevam vinistevam marked this pull request as ready for review July 26, 2024 12:14
@vinistevam vinistevam requested review from a team as code owners July 26, 2024 12:14
@vinistevam vinistevam force-pushed the feat/redesign-transaction-metrics-alerts branch from 9643393 to 5eea34a Compare July 26, 2024 13:11
return (
<ConfirmInfoRow
<ConfirmInfoAlertRow
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using ConfirmInfoAlertRow here to support the inline alert.

@MetaMask MetaMask deleted a comment from codecov bot Jul 26, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [4e65436]
Page Load Metrics (152 ± 184 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6571912613766
domContentLoaded8176363617
load401823152384184
domInteractive8176363617
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 7.32 KiB (0.10%)
  • common: 0 Bytes (0.00%)

{children}
</AlertMetricsContext.Provider>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We use context for shared state, but there is no shared state. Can we avoid creating this new context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I apologize for any confusion. I have now updated the PR description to explain the rationale behind this approach. The context is necessary to aggregate and persist state across multiple events (e.g., user clicks on inline alerts, visualizations, and action clicks) within the alert system. This ensures that all interactions are captured and combined into a single set of properties, which are then added to the transaction event. Without the context, we would not be able to maintain this aggregated state across different components effectively.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since hook useConfirmationAlertMetrics is not used outside the context, may be code can be embedded in context itself.

Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

});
});

describe('useConfirmationAlertMetrics', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it also be beneficial with a test (here or elsewhere) that no alert metrics are sent unless metametrics is enabled / user has opted in to analytics?

Copy link
Member

Choose a reason for hiding this comment

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

This is encapsulated within the MetaMetricsController in the backend as it won't actually submit anything if the metrics preference is disabled.

@metamaskbot
Copy link
Collaborator

Builds ready [32298a7]
Page Load Metrics (264 ± 279 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint782151093718
domContentLoaded94622115
load412086264581279
domInteractive94622115
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.57 KiB (0.09%)
  • common: 0 Bytes (0.00%)

});
});

describe('useConfirmationAlertMetrics', () => {
Copy link
Member

Choose a reason for hiding this comment

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

This is encapsulated within the MetaMetricsController in the backend as it won't actually submit anything if the metrics preference is disabled.

jpuri
jpuri previously approved these changes Jul 29, 2024
Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

Changes look good 👍

@metamaskbot
Copy link
Collaborator

Builds ready [04900f9]
Page Load Metrics (262 ± 268 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint723821227335
domContentLoaded10102312110
load472044262559268
domInteractive10102292110
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.58 KiB (0.09%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.14%. Comparing base (91dc6ea) to head (aa3aae0).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26121      +/-   ##
===========================================
+ Coverage    70.10%   70.14%   +0.04%     
===========================================
  Files         1430     1432       +2     
  Lines        50147    50216      +69     
  Branches     13872    13881       +9     
===========================================
+ Hits         35152    35221      +69     
  Misses       14995    14995              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [50fd47d]
Page Load Metrics (400 ± 389 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint672201113215
domContentLoaded96727178
load412825400809389
domInteractive96727178
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.58 KiB (0.09%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [dcb1364]
Page Load Metrics (231 ± 245 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint632151003818
domContentLoaded9173283517
load391990231511245
domInteractive9173283517
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.58 KiB (0.09%)
  • common: 0 Bytes (0.00%)

Copy link

@metamaskbot
Copy link
Collaborator

Builds ready [aa3aae0]
Page Load Metrics (156 ± 159 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint573811237938
domContentLoaded8182364220
load381578156331159
domInteractive8182364220
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.58 KiB (0.09%)
  • common: 0 Bytes (0.00%)

@vinistevam vinistevam merged commit bc6539b into develop Aug 12, 2024
78 checks passed
@vinistevam vinistevam deleted the feat/redesign-transaction-metrics-alerts branch August 12, 2024 10:06
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2024
@metamaskbot metamaskbot added the release-12.4.0 Issue or pull request that will be included in release 12.4.0 label Aug 12, 2024
@gauthierpetetin gauthierpetetin added release-12.3.0 Issue or pull request that will be included in release 12.3.0 and removed release-12.4.0 Issue or pull request that will be included in release 12.4.0 labels Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants