Skip to content

chore(homepage): homepage session summary segment event#26634

Merged
vinnyhoward merged 2 commits into
mainfrom
feat-tmcu-465-section-session-segment-event
Mar 6, 2026
Merged

chore(homepage): homepage session summary segment event#26634
vinnyhoward merged 2 commits into
mainfrom
feat-tmcu-465-section-session-segment-event

Conversation

@vinnyhoward
Copy link
Copy Markdown
Contributor

@vinnyhoward vinnyhoward commented Feb 26, 2026

Description

Adds a session_summary analytics event that fires when a user navigates away from the homepage. This completes the homepage sections analytics suite alongside the existing section_viewed event.

The event reuses the HOMEPAGE_SECTION_VIEWED Segment event with interaction_type: 'session_summary' and captures:

  • total_sections_viewed— how many sections reached ≥50% visibility this visit
  • total_sections_loaded — how many sections were enabled via feature flags
  • entry_point — how the user arrived (app_opened, home_tab, navigated_back)
  • session_time — seconds spent on the homepage
    location: 'home'

Implementation details:

  • New useHomepageSessionSummary hook owns all session tracking. All state lives in refs — zero re-renders on scroll or blur path.
  • Reacts to visitId increments from useHomepageEntryPoint to detect focus and reset per-visit state.
  • Fires on navigation blur via a stable ref-wrapped callback to avoid stale closures.
  • notifySectionViewed added to HomepageScrollContext so sections self-report views when their section_viewed event fires.

Segment Event PR: https://github.com/Consensys/segment-schema/pull/477

This PR needs to be merged first before review: #26529

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Homepage session summary analytics

  Scenario: user navigates away from the homepage
    Given the homepage sections feature flag is enabled
    And the user is on the homepage

    When user navigates to another screen (e.g. sends a transaction)
    Then a session_summary event fires with interaction_type "session_summary"
    And session_time reflects time spent on the homepage
    And total_sections_viewed reflects sections that entered the viewport

  Scenario: feature flag is disabled
    Given the homepage sections feature flag is disabled
    When user navigates away from the homepage
    Then no session_summary event is fired

Screenshots/Recordings

session.mov

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
Adds new analytics firing on homepage blur and expands HomepageScrollContext contract, which could affect event volume/accuracy if focus/visit tracking is wrong. Runtime risk is limited since it uses refs/sets and doesn’t change wallet transaction or account logic.

Overview
Adds a new homepage session summary analytics emission: useHomeSessionSummary fires MetaMetricsEvents.HOME_VIEWED with interaction_type: 'session_summary' when the homepage blurs, including session_time, entry_point, total_sections_loaded, and total_sections_viewed.

Extends HomepageScrollContext with notifySectionViewed/getViewedSectionCount; Wallet now tracks distinct viewed sections per visitId in a ref-backed Set, and useHomeViewedEvent reports section views into this aggregator. Includes new unit tests for the session-summary hook and updates existing section-view tests for the new context fields.

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

@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.

@metamaskbot metamaskbot added the team-mobile-ux Mobile UX team label Feb 26, 2026
Comment thread app/components/Views/Wallet/hooks/useHomepageSessionSummary.ts Outdated
@vinnyhoward vinnyhoward changed the title chore: homepage session summary segment event chore(homepage): homepage session summary segment event Feb 26, 2026
Base automatically changed from feat-tmcu-465-homepage-section-viewed-segment-event to main March 5, 2026 11:40
@vinnyhoward vinnyhoward requested a review from a team as a code owner March 5, 2026 11:40
@vinnyhoward vinnyhoward force-pushed the feat-tmcu-465-section-session-segment-event branch from 7ef7d6c to 6c1270c Compare March 6, 2026 06:10
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

// Reset viewed sections on each new visit so session summary starts fresh.
useEffect(() => {
viewedSectionsRef.current.clear();
}, [visitId]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition: non-rendered sections never counted in summary

Low Severity

Non-rendered sections (e.g. DeFi with no positions, where sectionRef is null) call notifySectionViewed synchronously inside a child useEffect triggered by visitId. The parent useEffect in Wallet that calls viewedSectionsRef.current.clear() is triggered by the same visitId change but runs after child effects (React's bottom-up effect ordering). This silently erases any sections added by the child, so non-rendered sections fire a section_viewed event but are never reflected in the session summary's total_sections_viewed, creating inconsistent analytics data.

Additional Locations (1)

Fix in Cursor Fix in Web

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are purely analytics-related, adding a new useHomeSessionSummary hook that fires a HOME_VIEWED analytics event when users navigate away from the homepage. The changes include:

  1. New useHomeSessionSummary hook - fires session summary analytics on blur
  2. Updated HomepageScrollContext - adds notifySectionViewed and getViewedSectionCount methods
  3. Updated useHomeViewedEvent - calls notifySectionViewed after section_viewed events
  4. Updated Wallet/index.tsx - implements the new context methods using a Set to track viewed sections
  5. Updated Homepage.tsx - uses the new hook

These changes:

  • Do NOT modify any UI or user-facing behavior
  • Only add analytics tracking for session summaries
  • Come with comprehensive unit tests (340+ lines of test code)
  • Use refs to avoid re-renders (performance-conscious implementation)

Since the changes touch the Wallet view and Homepage components (core wallet platform areas), selecting SmokeWalletPlatform provides basic validation that the wallet home screen still functions correctly. The risk is low because the changes are additive analytics code that doesn't modify existing functionality.

Performance Test Selection:
The changes are purely analytics-related and specifically designed to avoid performance impact. The implementation uses refs instead of state to prevent re-renders, and the analytics events only fire on blur (when leaving the homepage). The code explicitly states 'All session state is held in refs — no re-renders occur on scroll or blur.' There are no changes to UI rendering, data loading, or any performance-critical paths. No performance tests are needed.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

⚠️ E2E Fixture Validation — Structural changes detected

Category Count
New keys 68
Missing keys 11
Type mismatches 0
Value mismatches 7 (informational)

The committed fixture schema is out of date. To update, comment:

@metamaskbot update-mobile-fixture

View full details | Download diff report

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 6, 2026

@vinnyhoward vinnyhoward enabled auto-merge March 6, 2026 07:30
@vinnyhoward vinnyhoward added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 7243904 Mar 6, 2026
93 checks passed
@vinnyhoward vinnyhoward deleted the feat-tmcu-465-section-session-segment-event branch March 6, 2026 08:37
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 6, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 size-M team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants