Skip to content

fix: only fire APP_OPENED on background → active transition#27463

Open
vinnyhoward wants to merge 1 commit intomainfrom
fix-tmcu-256-inaccurate-app-opens-qr-scanner
Open

fix: only fire APP_OPENED on background → active transition#27463
vinnyhoward wants to merge 1 commit intomainfrom
fix-tmcu-256-inaccurate-app-opens-qr-scanner

Conversation

@vinnyhoward
Copy link
Contributor

@vinnyhoward vinnyhoward commented Mar 13, 2026

Description

When the QR scanner on iPhone prompts the user to grant camera access, iOS transitions the app to inactive (not background). If the user taps "Cancel" on the permission dialog, the app returns to active, which was incorrectly triggering the App Opened analytics event.

The fix tightens the condition in AppStateEventListener to only fire APP_OPENED when transitioning from background → active, which represents the user genuinely re-opening the app. Transitions from inactive → active (system dialogs, incoming calls, etc.) are now correctly ignored.

Changelog

CHANGELOG entry:null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-256

Manual testing steps

Feature: App Opened analytics event

  Scenario: user dismisses camera permission dialog from QR scanner
    Given the user has not granted camera access to MetaMask
    And the user is on any screen in the app

    When user taps the QR scanner icon
    And the iOS camera permission dialog appears
    And user taps "Cancel" on the dialog

    Then the App Opened analytics event is NOT fired

  Scenario: user opens the app from the background
    Given the user has backgrounded the app

    When user returns to the app from the app switcher or home screen

    Then the App Opened analytics event IS fired

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.

Note

Medium Risk
Changes the gating logic for when APP_OPENED is emitted, which can impact analytics counts and attribution if the app state transitions are misclassified on some platforms.

Overview
Tightens APP_OPENED tracking to reduce false positives. AppStateEventListener now triggers the event only on backgroundactive transitions, and explicitly ignores inactiveactive returns (e.g., iOS permission dialogs/calls).

Tests are updated to reflect the required backgroundactive sequence for firing, and add coverage to ensure APP_OPENED does not re-fire on repeated active states or on inactiveactive transitions.

Written by Cursor Bugbot for commit dd64cc6. This will update automatically on new commits. Configure here.

@github-actions
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-mobile-ux Mobile UX team label Mar 13, 2026
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
The change refines analytics behavior in AppStateEventListener to only fire APP_OPENED on background→active transitions. It does not affect controllers, navigation, confirmations, accounts, networks, swaps, snaps, identity, or any UI flows covered by Detox E2E tests. No shared components (Browser, TabBar, Confirmations, Engine, controllers) were modified. E2E tests do not assert analytics behavior or depend on inactive/background transitions. Therefore no E2E coverage is required.

Performance Test Selection:
The change only tightens a conditional check for analytics firing. No UI rendering, controller state management, asset loading, navigation, or startup logic was modified. No performance impact expected.

View GitHub Actions results

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants