Skip to content

feat: track active tab domain and environment type on SwapBridge events#43540

Draft
ameliejyc wants to merge 15 commits into
mainfrom
CEUX-1092-track-active-tab-domain-on-in-app-events-allowlist-only-x-com-v-1-2
Draft

feat: track active tab domain and environment type on SwapBridge events#43540
ameliejyc wants to merge 15 commits into
mainfrom
CEUX-1092-track-active-tab-domain-on-in-app-events-allowlist-only-x-com-v-1-2

Conversation

@ameliejyc

@ameliejyc ameliejyc commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

Depends on MetaMask/core#9121.

Extends Unified SwapBridge MetaMetrics events:

  1. active_tab_domain on Submitted and ButtonClicked events — Adds the active browser tab's origin as active_tab_domain to Unified SwapBridge Submitted and Unified SwapBridge ButtonClicked events. The property is allowlist-gated: only origins matching the LaunchDarkly-sourced extension-ux-active-domain-metrics flag (default: x.com, twitter.com) are recorded.

  2. environment_type promoted to top-level MetaMetrics field for all SwapBridge eventsenvironment_type was previously embedded inside the properties bag. It is now hoisted to the top-level environmentType field on the trackEvent payload, consistent with how other MetaMask events are tracked. This fixes a bug where both environmentType and environment_type were showing in these metrics.

  3. For the UI-triggered event Unified SwapBridge ButtonClicked, the UI passes environment_type explicitly so the accurate popup/sidepanel/fullscreen context is captured; background-originated events fall back to getEnvironmentType() (which returns 'background').

A change on @metamask/bridge-controller adds environment_type?: string to the RequiredEventContextFromClientBase[ButtonClicked] type so the UI can pass the property without a type error.

Changelog

CHANGELOG entry: null

Related issues

Fixes: CEUX-1092

Manual testing steps

  1. Open MetaMask as a popup while the active tab is x.com
  2. Navigate to the Swap/Bridge screen and click the Bridge button — verify the Unified SwapBridge ButtonClicked Segment event includes active_tab_domain: "https://x.com" and environment_type: "popup" at the top level
  3. Submit a bridge transaction — verify Unified SwapBridge Submitted includes active_tab_domain
  4. Repeat with the active tab set to a non-allowlisted domain (e.g. google.com) — verify active_tab_domain is absent from both events
  5. Open MetaMask as a full-screen page and repeat — verify environment_type reflects "fullscreen"

Expected payloads:

"event": "Unified SwapBridge Button Clicked",
    "type": "track",
    "properties": {
        "chain_id_source": "eip155:1",
        "chain_id_destination": null,
        "token_address_source": "eip155:1/slip44:60",
        "token_address_destination": null,
        "token_security_type_destination": null,
        "location": "Main View",
        "token_symbol_source": "ETH",
        "token_symbol_destination": "",
        "action_type": "swapbridge-v1",
        "active_tab_domain": "https://x.com", // new property shows when on twitter
        "actionId": "1781513409972.1033",
        "category": "Unified SwapBridge",
        "locale": "en",
        "chain_id": "0x1",
        "environment_type": "sidepanel" // note this can now be any value, not just 'background'
    },

{
    "event": "Unified SwapBridge Submitted",
    "type": "track",
    "properties": {
        "action_type": "swapbridge-v1",
        "price_impact": -0.0009799897908718681,
        "usd_quoted_gas": 0.00035489797924277233,
        "gas_included": false,
        "gas_included_7702": false,
        "provider": "jupiter_1DEX",
        "quoted_time_minutes": 0,
        "usd_quoted_return": 0.00672906259193776,
        "chain_id_source": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
        "token_symbol_source": "SOL",
        "token_address_source": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
        "chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
        "token_symbol_destination": "USDC",
        "token_address_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "token_security_type_destination": null,
        "account_hardware_type": null,
        "is_hardware_wallet": false,
        "swap_type": "single_chain",
        "usd_amount_source": 0.007097959584855446,
        "stx_enabled": false,
        "custom_slippage": false,
        "location": "Main View",
        "active_tab_domain": "https://x.com", // new property shows when on twitter
        "actionId": "1781518909262.0999",
        "category": "Unified SwapBridge",
        "locale": "en",
        "chain_id": "0x1",
        "environment_type": "background" // still only 'background' value for this event
    },
}

Screenshots/Recordings

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.

@github-actions

Copy link
Copy Markdown
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.

@mm-token-exchange-service

mm-token-exchange-service Bot commented Jun 15, 2026

Copy link
Copy Markdown

✨ Files requiring CODEOWNER review ✨

🔄 @MetaMask/swaps-engineers (2 files, +7 -0)
  • 📁 ui/
    • 📁 hooks/
      • 📁 bridge/
        • 📄 useBridging.test.ts +4 -0
        • 📄 useBridging.ts +3 -0

@mm-token-exchange-service mm-token-exchange-service Bot added the team-core-extension-ux Core Extension UX team label Jun 15, 2026
@mm-token-exchange-service

Copy link
Copy Markdown
Builds ready [642f210] [reused from 38a1bc4]
Deprecated Browserify fallback builds
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 8 warn · 🔴 0 fail)

Baseline (latest main): 5682526 | Date: 6/13/2026 | Pipeline: 27538332197 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-webpackfirefox-webpack
loadNewAccount
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
🔴 load_new_account
confirmTx
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
bridgeUserActions
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/tbt: +22%
  • bridgeUserActions/inp: -24%
  • loadNewAccount/load_new_account: +645%
  • loadNewAccount/total: +645%
  • loadNewAccount/lcp: +1095%
  • confirmTx/confirm_tx: +13%
  • confirmTx/longTaskCount: -100%
  • confirmTx/longTaskTotalDuration: -100%
  • confirmTx/longTaskMaxDuration: -100%
  • confirmTx/tbt: -100%
  • confirmTx/total: +13%
  • confirmTx/fcp: +10%
  • confirmTx/lcp: +1125%
  • bridgeUserActions/bridge_load_page: +58%
  • bridgeUserActions/bridge_load_asset_picker: +80%
  • bridgeUserActions/longTaskCount: -100%
  • bridgeUserActions/longTaskTotalDuration: -100%
  • bridgeUserActions/longTaskMaxDuration: -100%
  • bridgeUserActions/tbt: -100%
  • bridgeUserActions/inp: -24%
  • bridgeUserActions/fcp: +10%
  • bridgeUserActions/lcp: +1226%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 1.9s
  • 🟡 confirmTx/FCP: p75 1.8s
  • 🟡 bridgeUserActions/FCP: p75 1.8s
Startup Benchmarks · Samples: 100
Benchmarkchrome-webpackfirefox-webpack
startupStandardHome
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
startupPowerUserHome
[Sentry log · main/release]
🟡 [CI log]🟡 [CI log]

📈 Results compared to the previous 5 runs on main

  • startupPowerUserHome/backgroundConnect: +11%
  • startupPowerUserHome/numNetworkReqs: -30%
  • startupStandardHome/inp: +50%
  • startupPowerUserHome/backgroundConnect: -40%
  • startupPowerUserHome/setupStore: +34%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 528ms
  • 🟡 startupPowerUserHome/LCP: p75 2.9s
User Journey Benchmarks · Samples: 5 · mock API

⚠️ Missing data: firefox/webpack/userJourneyTransactions

Benchmarkchrome-webpackfirefox-webpack
onboardingImportWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
onboardingNewWallet
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
🟡 total
assetDetails
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
solanaAssetDetails
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
importSrpHome
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
sendTransactions
[Sentry log · main/release]
🟢 [CI log]
swap
[Sentry log · main/release]
🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/doneButtonToHomeScreen: -87%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: -97%
  • onboardingImportWallet/longTaskCount: -55%
  • onboardingImportWallet/longTaskTotalDuration: -86%
  • onboardingImportWallet/longTaskMaxDuration: -88%
  • onboardingImportWallet/tbt: -97%
  • onboardingImportWallet/total: -85%
  • onboardingNewWallet/srpButtonToPwForm: -33%
  • onboardingNewWallet/createPwToRecoveryScreen: -28%
  • onboardingNewWallet/skipBackupToMetricsScreen: -23%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -48%
  • onboardingNewWallet/doneButtonToAssetList: -68%
  • onboardingNewWallet/longTaskCount: -100%
  • onboardingNewWallet/longTaskTotalDuration: -100%
  • onboardingNewWallet/longTaskMaxDuration: -100%
  • onboardingNewWallet/tbt: -100%
  • onboardingNewWallet/total: -61%
  • solanaAssetDetails/assetClickToPriceChart: +89%
  • solanaAssetDetails/longTaskCount: +400%
  • solanaAssetDetails/longTaskTotalDuration: +400%
  • solanaAssetDetails/longTaskMaxDuration: +400%
  • solanaAssetDetails/tbt: +400%
  • solanaAssetDetails/total: +89%
  • solanaAssetDetails/cls: -89%
  • importSrpHome/loginToHomeScreen: -20%
  • importSrpHome/openAccountMenuAfterLogin: +42%
  • importSrpHome/homeAfterImportWithNewWallet: -39%
  • importSrpHome/longTaskCount: -31%
  • importSrpHome/longTaskTotalDuration: -32%
  • importSrpHome/longTaskMaxDuration: -14%
  • importSrpHome/tbt: -34%
  • importSrpHome/total: -34%
  • importSrpHome/inp: -25%
  • sendTransactions/selectTokenToSendFormLoaded: +48%
  • sendTransactions/reviewTransactionToConfirmationPage: -14%
  • sendTransactions/total: -13%
  • sendTransactions/inp: -27%
  • sendTransactions/cls: -89%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/FCP: p75 1.8s
  • 🟡 importSrpHome/FCP: p75 1.9s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-webpack
dappPageLoad
[Sentry log · main/release]
🟢 [CI log]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 700 Bytes (0.01%)
  • ui: 20.39 KiB (0.18%)
  • common: 1.37 KiB (0.01%)

amitabh94 pushed a commit to amitabh94/core that referenced this pull request Jun 16, 2026
…icked event properties (MetaMask#9121)

## Explanation

For this [core extension UX
ticket](https://consensyssoftware.atlassian.net/browse/CEUX-1092), we
want to embellish the Unified SwapBridge Button Clicked event with the
`environment_type` of the UI context. These metrics do already include
environment type, but they always have the value `background` as that is
the context used when they are emitted. We want to however have the UI
context for this metric so we can track `sidepanel` vs `popup` etc.

So this PR modifies the `Unified SwapBridge Button Clicked` event
properties (exported via `RequiredEventContextFromClient` in
`@metamask/bridge-controller`) to add optional `environment_type` to be
able to pass this data in directly at the call site where the values are
either `sidepanel`, `popup` or `fullscreen`. Client side PR
[here](MetaMask/metamask-extension#43540).

## References

* Part fixes: https://consensyssoftware.atlassian.net/browse/CEUX-1092

## 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
- [x] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-S team-core-extension-ux Core Extension UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant