Skip to content

Commit a37efd8

Browse files
authored
chore: emit new Viewport Switched event for sidepanel popup toggle (#37716)
## **Description** This PR introduces a new MetaMetrics event `Viewport Switched` to track when users toggle between the popup and sidepanel views in the extension. The `App Window Expanded` event in the Global Menu is still used for the Expand View button. **What is the reason for the change?** The existing `App Window Expanded` event didn't capture sufficient information about viewport transitions so we have introduced a new metric. **What is the improvement/solution?** - Added a new `ViewportSwitched` MetaMetrics event (experimental build only) - Updated the Global Menu's viewport toggle to emit this new event - Enhanced event properties to include a `to` field that specifies the target viewport (`popup` or `sidepanel`) **Example event emitted:** ```json { "location": "Global Menu", "to": "sidepanel", "category": "Navigation", "locale": "en", "chain_id": "0x1", "environment_type": "popup" } ``` [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/37716?quickstart=1) ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/CEUX-487 ## **Manual testing steps** 1. Build the extension with experimental features enabled `yarn start --build-type experimental` 2. Also run the Segment mock API `node development/mock-segment.js` 3. Open the extension popup 4. Click on the hamburger menu (three dots) in the top right 5. Toggle the "Sidepanel view" / "Popup view" option 6. Check the console to verify the `Viewport Switched` event is emitted with the correct `to` property ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** The existing event was being emitted for the sidebar/popup view button: Event: `App Window Expanded` Properties: `{ location: "Global Menu" }` ### **After** Now sidepanel/popup button has its own dedicated metric: Event: `Viewport Switched` Properties: `{ location: "Global Menu", to: "sidepanel" }` or `{ location: "Global Menu", to: "popup" }` ## **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 - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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] > Introduce experimental Viewport Switched metric and emit it from Global Menu toggle with target viewport, keeping App Window Expanded for expand view. > > - **Metrics**: > - Add experimental `MetaMetricsEventName.ViewportSwitched`. > - **Global Menu** (`ui/components/multichain/global-menu/global-menu.tsx`): > - Toggle between popup/sidepanel now tracks `ViewportSwitched` with `properties.to` set to `popup` or `sidepanel`. > - Keep `App Window Expanded` for the expand-to-tab action when sidepanel is unavailable or on Firefox. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0d12473. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5777c00 commit a37efd8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

shared/constants/metametrics.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ export enum MetaMetricsEventName {
942942
ExtensionPinned = 'Extension Pinned',
943943
// Extension Port Stream
944944
PortStreamChunked = 'Port Stream Chunked',
945+
///: BEGIN:ONLY_INCLUDE_IF(build-experimental)
946+
ViewportSwitched = 'Viewport Switched',
947+
///: END:ONLY_INCLUDE_IF
945948
}
946949

947950
export enum MetaMetricsEventAccountType {

ui/components/multichain/global-menu/global-menu.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,13 @@ export const GlobalMenu = ({
402402
onClick={async () => {
403403
await toggleDefaultView();
404404
trackEvent({
405-
event: MetaMetricsEventName.AppWindowExpanded,
405+
event: MetaMetricsEventName.ViewportSwitched,
406406
category: MetaMetricsEventCategory.Navigation,
407407
properties: {
408408
location: METRICS_LOCATION,
409+
to: isSidePanelDefault
410+
? ENVIRONMENT_TYPE_POPUP
411+
: ENVIRONMENT_TYPE_SIDEPANEL,
409412
},
410413
});
411414
closeMenu();

0 commit comments

Comments
 (0)