Skip to content

Commit 8401e68

Browse files
authored
feat!: add time-based delay for first metrics sending (#7624)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> `ProfileMetricsController` is being overhauled to rely on a timestamp-based delay for the first sending of metrics, rather than waiting for a second App Unlock event. This change ensures that metrics are sent even if the user only unlocks the app once during a session. The delay is skipped immediately if: - A transaction is submitted - The user is already opted-in when `KeyringController:unlock` is fired (this covers both users who have opted-in in a previous session, and users who just onboarded and opted-in during onboarding). - The consumer client calls the `.skipInitialDelay()` method or the `ProfileMetricsController:skipInitialDelay` action via messenger. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces a timestamp-based initial delay for first profile metrics send, with configurable duration and multiple skip paths. > > - Add `initialDelayEndTimestamp` state and default 10-minute delay; constructor accepts `initialDelayDuration` > - New `skipInitialDelay()` method and `ProfileMetricsController:skipInitialDelay` action; auto-skip on `KeyringController:unlock` when already opted-in and on `TransactionController:transactionSubmitted` > - Polling now starts on unlock; `_executePoll` exits until delay completes; state metadata updated to persist/expose new field > - BREAKING: messenger must allow `TransactionController:transactionSubmitted`; add `@metamask/transaction-controller` dependency and TS references; export new method-action types; tests and README dependency graph updated > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0237820. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9dbe5d1 commit 8401e68

File tree

10 files changed

+378
-128
lines changed

10 files changed

+378
-128
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ linkStyle default opacity:0.5
185185
app_metadata_controller --> messenger;
186186
approval_controller --> base_controller;
187187
approval_controller --> messenger;
188+
assets_controller --> base_controller;
189+
assets_controller --> messenger;
188190
assets_controllers --> account_tree_controller;
189191
assets_controllers --> accounts_controller;
190192
assets_controllers --> approval_controller;
@@ -357,6 +359,7 @@ linkStyle default opacity:0.5
357359
profile_metrics_controller --> messenger;
358360
profile_metrics_controller --> polling_controller;
359361
profile_metrics_controller --> profile_sync_controller;
362+
profile_metrics_controller --> transaction_controller;
360363
profile_sync_controller --> address_book_controller;
361364
profile_sync_controller --> base_controller;
362365
profile_sync_controller --> keyring_controller;

packages/profile-metrics-controller/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `ProfileMetricsController` contructor now accepts an optional `initialDelayDuration` parameter ([#7624](https://github.com/MetaMask/core/pull/7624))
13+
- The parameter can be used to override the default time-based delay for the first data collection after opt-in
14+
- Add `skipInitialDelay()` method to `ProfileMetricsController` ([#7624](https://github.com/MetaMask/core/pull/7624))
15+
- The method can be also called through the `ProfileMetricsController:skipInitialDelay` action via messenger
16+
1017
### Changed
1118

19+
- **BREAKING:** `ProileMetricsControllerMessenger` now requires the `TransactionController:transactionSubmitted` action to be allowed ([#7624](https://github.com/MetaMask/core/pull/7624))
20+
- Set time-based delay for first `ProfileMetricsController` data collection after opt-in ([#7624](https://github.com/MetaMask/core/pull/7624))
1221
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
1322
- Bump `@metamask/controller-utils` from `^11.16.0` to `^11.18.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583))
1423
- Bump `@metamask/accounts-controller` from `^35.0.0` to `^35.0.2` ([#7604](https://github.com/MetaMask/core/pull/7604), [#7642](https://github.com/MetaMask/core/pull/7642))

packages/profile-metrics-controller/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@metamask/messenger": "^0.3.0",
5656
"@metamask/polling-controller": "^16.0.2",
5757
"@metamask/profile-sync-controller": "^27.0.0",
58+
"@metamask/transaction-controller": "^62.9.2",
5859
"@metamask/utils": "^11.9.0",
5960
"async-mutex": "^0.5.0"
6061
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
3+
* Do not edit manually.
4+
*/
5+
6+
import type { ProfileMetricsController } from './ProfileMetricsController';
7+
8+
/**
9+
* Skip the initial delay period by setting the end timestamp to the current time.
10+
* Metrics will be sent on the next poll.
11+
*/
12+
export type ProfileMetricsControllerSkipInitialDelayAction = {
13+
type: `ProfileMetricsController:skipInitialDelay`;
14+
handler: ProfileMetricsController['skipInitialDelay'];
15+
};
16+
17+
/**
18+
* Union of all ProfileMetricsController action types.
19+
*/
20+
export type ProfileMetricsControllerMethodActions =
21+
ProfileMetricsControllerSkipInitialDelayAction;

0 commit comments

Comments
 (0)