release(runway): cherry-pick feat: analytics pref tracking for social onboarding cp-13.25.0#41388
Merged
Merged
Conversation
… onboarding cp-13.25.0 (#41343) <!-- 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** This PR closes a gap in `Analytics Preference Selected` tracking for social login users and makes the event payload consistent across the other consent surfaces. Social login users do not go through the standard onboarding MetaMetrics screen, so this adds tracking when they make that preference implicitly during create-password onboarding and when returning social-login users are rehydrated from backup. It also aligns the standard onboarding, settings, and home consent flows to use the same `MetaMetricsUserTrait` payload fields, and adds unit coverage for the social backup restore path. This PR also fixes ~ - Fixed the real race in ui/contexts/metametrics.tsx: MetaMetricsProvider was treating `participateInMetaMetrics === true` as “ready to send”, even when metaMetricsId had not been created yet. - That mismatch caused `Analytics Preference Selected` to go down the immediate-send path and get dropped by the background layer before it could reach Segment. - Updated the provider so events are only sent immediately when both conditions are true: - metrics participation is enabled - metaMetricsId exists - If the ID is still missing, the provider now buffers the event through `addEventBeforeMetricsOptIn`, which matches the real onboarding flow better. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: #41378 ## **Manual testing steps** 1. Go through the standard onboarding flow to the MetaMetrics screen, opt in, and verify `Analytics Preference Selected` fires with `location: onboarding_metametrics` and the expected consent values. 2. Go through the social login onboarding flow to the create-password step with the consent checkbox checked and unchecked, and verify the event fires with `location: onboarding_create_password` and the correct `has_marketing_consent` value. 3. Rehydrate an existing social-login user through the unlock/restore flow and verify the event fires with `location: onboarding_social_login_rehydration` after marketing consent is synced from background state. 4. Toggle MetaMetrics / marketing consent from Settings and the home marketing consent modal and verify `Analytics Preference Selected` uses the standardized user trait fields and expected opt-in / consent values. <!-- ## **Screenshots/Recordings** ### **Before** N/A ### **After** N/A --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] 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-extension/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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes MetaMetrics event dispatch conditions and adds new onboarding tracking paths, which could affect when/if analytics events are sent during critical onboarding flows. Test updates and new provider unit coverage reduce risk but regressions could still drop or duplicate events. > > **Overview** > Adds missing `AnalyticsPreferenceSelected` tracking for *social login* users during `create-password` and during social-backup rehydration, and wires `trackEvent` through `restoreSocialBackupAndGetSeedPhrase` to emit the event after marketing-consent sync. > > Fixes a metrics dispatch race by making `MetaMetricsProvider` only send events immediately when **both** `participateInMetaMetrics` is enabled and a `metaMetricsId` exists; otherwise events are buffered via `addEventBeforeMetricsOptIn` (except `MetricsOptOut`). > > Standardizes consent-related event properties across onboarding, Home, and Settings to use `MetaMetricsUserTrait` keys, and updates/extends tests (new `ui/contexts/metametrics.test.tsx`, integration/e2e fixtures, and additional API nocks) plus console baselines accordingly. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1223d6d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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. |
Contributor
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/core-extension-ux (1 files, +3 -2)
🔐 @MetaMask/web3auth (3 files, +25 -11)
|
Contributor
Builds ready [1d64c2e]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Contributor
Builds ready [bf8aa5b]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
This PR closes a gap in
Analytics Preference Selectedtracking forsocial login users and makes the event payload consistent across the
other consent surfaces.
Social login users do not go through the standard onboarding MetaMetrics
screen, so this adds tracking when they make that preference implicitly
during create-password onboarding and when returning social-login users
are rehydrated from backup. It also aligns the standard onboarding,
settings, and home consent flows to use the same
MetaMetricsUserTraitpayload fields, and adds unit coverage for the social backup restore
path.
This PR also fixes ~
MetaMetricsProvider was treating
participateInMetaMetrics === trueas“ready to send”, even when metaMetricsId had not been created yet.
Analytics Preference Selectedto go down theimmediate-send path and get dropped by the background layer before it
could reach Segment.
conditions are true:
addEventBeforeMetricsOptIn, which matches the real onboarding flowbetter.
Changelog
CHANGELOG entry: null
Related issues
Fixes: #41378
Manual testing steps
opt in, and verify
Analytics Preference Selectedfires withlocation: onboarding_metametricsand the expected consent values.step with the consent checkbox checked and unchecked, and verify the
event fires with
location: onboarding_create_passwordand the correcthas_marketing_consentvalue.flow and verify the event fires with
location: onboarding_social_login_rehydrationafter marketing consent is syncedfrom background state.
marketing consent modal and verify
Analytics Preference Selectedusesthe standardized user trait fields and expected opt-in / consent values.
Pre-merge author checklist
Docs and MetaMask
Extension Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Medium Risk
Changes MetaMetrics event dispatch conditions and adds new onboarding
tracking paths, which could affect when/if analytics events are sent
during critical onboarding flows. Test updates and new provider unit
coverage reduce risk but regressions could still drop or duplicate
events.
Overview
Adds missing
AnalyticsPreferenceSelectedtracking for social loginusers during
create-passwordand during social-backup rehydration, andwires
trackEventthroughrestoreSocialBackupAndGetSeedPhraseto emitthe event after marketing-consent sync.
Fixes a metrics dispatch race by making
MetaMetricsProvideronlysend events immediately when both
participateInMetaMetricsisenabled and a
metaMetricsIdexists; otherwise events are buffered viaaddEventBeforeMetricsOptIn(exceptMetricsOptOut).Standardizes consent-related event properties across onboarding, Home,
and Settings to use
MetaMetricsUserTraitkeys, and updates/extendstests (new
ui/contexts/metametrics.test.tsx, integration/e2e fixtures,and additional API nocks) plus console baselines accordingly.
Written by Cursor
Bugbot for commit
1223d6d. This will update automatically
on new commits. Configure
here.