Skip to content

chore: add more metrics to trending flow#25375

Merged
sahar-fehri merged 12 commits intomainfrom
chore/add-trending-metrics
Jan 30, 2026
Merged

chore: add more metrics to trending flow#25375
sahar-fehri merged 12 commits intomainfrom
chore/add-trending-metrics

Conversation

@sahar-fehri
Copy link
Copy Markdown
Contributor

@sahar-fehri sahar-fehri commented Jan 29, 2026

Description

This PR extends the TRENDING_FEED_VIEWED analytics event with an interaction_type discriminator pattern to track detailed user interactions within the Trending feed.

Related: https://github.com/Consensys/segment-schema/pull/440

Background

The existing TRENDING_FEED_VIEWED event (PR #23674) tracks session-level metrics (session_id, session_time, entry_point, is_session_end). This PR adds granular interaction tracking.

Changes

  1. Added interaction_type discriminator - All events now include an interaction_type field to distinguish between: session_start, session_end, token_click, search, filter_change

  2. Token Click Tracking - Tracks when users tap on tokens from the Trending feed, including position, price data, and active filter context

  3. Search Tracking - Tracks search queries with debounce (500ms), including result counts and filter context

  4. Filter Change Tracking - Tracks when users change time, sort, or network filters, including previous and new values

  5. Filter Context Propagation - Added TrendingFilterContext interface and propagated it through TrendingTokensListTrendingTokenRowItem for analytics context


Debug Console Logs for Testing

Temporary console.logs have been added to help verify the events fire correctly.

File: app/components/UI/Trending/services/TrendingFeedSessionManager.ts

Session Start/End (in trackEvent method, after line 256):

// Add after: const analyticsProperties = { ... };
console.log(
  `${isSessionEnd ? '🛑' : '🚀'} TRENDING_FEED_VIEWED [${interactionType}]`,
  analyticsProperties,
);

Token Click / Search / Filter Change (in trackInteraction method, after line 296):

// Add after: const analyticsProperties = { ... };
const emoji = {
  token_click: '🔥',
  search: '🔍',
  filter_change: '⚙️',
}[interactionType] || '📊';
console.log(`${emoji} TRENDING_FEED_VIEWED [${interactionType}]`, analyticsProperties);

New Analytics Attributes

Interaction Types

interaction_type Description
session_start Fired when user enters Trending feed
session_end Fired when user leaves Trending feed
token_click Fired when user taps on a token
search Fired when user searches (debounced 500ms)
filter_change Fired when user changes time/sort/network filter

Token Click Properties (when interaction_type = token_click)

Property Type Description
token_symbol string Token symbol clicked (e.g., "ETH")
token_address string Token contract address
token_name string Token display name
chain_id string Network chain ID (hex format)
position integer 0-indexed position in list
price_usd number Token price at click time (USD)
price_change_pct number Price change percentage
time_filter string Active time filter (e.g., "24h", "6h", "1h", "5m")
sort_option string Active sort option (e.g., "price_change", "volume")
network_filter string Active network filter ("all" or chain ID)
is_search_result boolean Was this from search results?

Search Properties (when interaction_type = search)

Property Type Description
search_query string The search query entered
results_count integer Number of results returned
has_results boolean Whether search returned any results
time_filter string Active time filter
sort_option string Active sort option
network_filter string Active network filter

Filter Change Properties (when interaction_type = filter_change)

Property Type Description
filter_type string Type of filter changed: "time", "sort", or "network"
previous_value string Previous filter value
new_value string New filter value
time_filter string Active time filter
sort_option string Active sort option
network_filter string Active network filter

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Trending Feed Analytics Tracking

  Scenario: User clicks on a token from Trending feed
    Given the user is on the Trending feed (via homepage or Trade button)
    When user taps on a token in the list
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="token_click"
    And the event includes token_symbol, position, price data, and filter context
    And console shows "🔥 TRENDING_FEED_VIEWED [token_click]" with properties

  Scenario: User searches for a token
    Given the user is on the Trending full view
    When user types a search query and waits 500ms
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="search"
    And the event includes search_query, results_count, and has_results
    And console shows "🔍 TRENDING_FEED_VIEWED [search]" with properties

  Scenario: User changes the time filter
    Given the user is on the Trending full view with 24h filter active
    When user changes the time filter to 6h
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="filter_change"
    And filter_type="time", previous_value="24h", new_value="6h"
    And console shows "⚙️ TRENDING_FEED_VIEWED [filter_change]" with properties

  Scenario: User changes the network filter
    Given the user is on the Trending full view with "all" networks
    When user selects a specific network (e.g., Ethereum)
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="filter_change"
    And filter_type="network" with previous and new chain IDs
    And console shows "⚙️ TRENDING_FEED_VIEWED [filter_change]" with properties

  Scenario: Session tracking includes interaction_type
    Given the user opens the Trending feed
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="session_start"
    And console shows "🚀 TRENDING_FEED_VIEWED [session_start]"
    When user navigates away from Trending
    Then a TRENDING_FEED_VIEWED event fires with interaction_type="session_end"
    And console shows "🛑 TRENDING_FEED_VIEWED [session_end]"

Screenshots/Recordings

Before

After

Uploading Screen Recording 2026-01-29 at 17.35.57.mov…

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
Medium risk because it changes tab-switching behavior via a new onLeave hook and adds new analytics side effects (session start/end, search debounce) across multiple Trending entry points, which could impact navigation timing and event volume.

Overview
Expands Trending analytics from session-only to interaction-level tracking. TrendingFeedSessionManager now emits TRENDING_FEED_VIEWED events with an interaction_type discriminator (start/end, token_click, search, filter_change) and exposes new tracking helpers.

Trending UI now propagates a TrendingFilterContext through TrendingTokensList/TrendingTokenRowItem to record token click position, pricing, and active filters, adds a debounced useSearchTracking hook for search events (used in both the full Trending tokens view and Explore search), and tracks filter changes when time/sort/network selections change.

Navigation updates add a tab-level onLeave callback and invoke it on tab switches; the Trending tab uses this to start sessions on press and end sessions when leaving the tab.

Written by Cursor Bugbot for commit dbfeda0. 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.

@github-actions github-actions bot added size-XL and removed size-L labels Jan 29, 2026

// TODO: Remove before merging - temporary debug log
// eslint-disable-next-line no-console
console.log('🔍 TRENDING_FEED_VIEWED [search]', analyticsProperties);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODO remove


// TODO: Remove before merging - temporary debug log
// eslint-disable-next-line no-console
console.log('⚙️ TRENDING_FEED_VIEWED [filter_change]', analyticsProperties);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

to be removed

@sahar-fehri
Copy link
Copy Markdown
Contributor Author

sahar-fehri commented Jan 29, 2026

⚠️ I noticed that the Trending feed does not fire session_end when users switch tabs because it's embedded in a Bottom Tab Navigator, where screens remain mounted when switching away.

The session cleanup in here uses useEffect, which only runs on unmount—not on tab switch.
Note: the session end is fired correctly when the app goes to background

The Predict flow works correctly because they have a "Back" button which actually unmounts the screen, triggering the cleanup.

Any advices on how this can be fixed?

Update: fixed here c5a94fe

@sahar-fehri sahar-fehri marked this pull request as ready for review January 29, 2026 15:15
@sahar-fehri sahar-fehri requested a review from a team as a code owner January 29, 2026 15:15
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
This PR adds comprehensive analytics tracking for the Trending Feed feature. The changes include:

  1. TabBar Component Enhancement: Added onLeave callback to tab options - this is a core navigation component, but the change is additive (optional callback) and shouldn't break existing functionality.

  2. TrendingFeedSessionManager: New singleton service for tracking Trending Feed sessions with interaction types (SessionStart, SessionEnd, TokenClick, Search, FilterChange).

  3. MainNavigator Integration: Integrates session management with the Trending tab, starting/ending sessions when entering/leaving the tab.

  4. Component Updates: TrendingTokenRowItem, TrendingTokensList, TrendingTokensFullView, ExploreSearchResults, SectionCard, SectionCarrousel, and sections.config.tsx all updated to pass position and filter context for analytics tracking.

  5. New useSearchTracking hook: Debounced search event tracking.

The Trending feature has dedicated E2E tests in e2e/specs/trending/ that are tagged with SmokeWalletPlatform. These tests cover:

  • Trending Feed navigation
  • Trending search functionality
  • Trending browser integration

Running SmokeWalletPlatform will verify that:

  • The Trending tab navigation still works correctly with the new onLeave callback
  • Token clicks, searches, and filter changes function properly
  • The session management doesn't interfere with user interactions

The changes are primarily analytics additions and don't modify core business logic, but the TabBar modification and session management integration warrant verification through E2E tests.

Performance Test Selection:
The changes in this PR are focused on analytics tracking for the Trending Feed feature. The additions include:

  1. Event tracking calls (MetaMetrics.trackEvent) - lightweight operations
  2. Session management (start/end sessions) - minimal overhead
  3. Filter context passing through components - no rendering impact
  4. useSearchTracking hook with debouncing - actually reduces unnecessary operations

These analytics changes don't impact:

  • UI rendering performance (no new components or heavy renders)
  • Data loading (no changes to API calls or state management)
  • App startup or initialization
  • Critical user flows (analytics is fire-and-forget)

The changes are additive tracking code that runs asynchronously and doesn't block user interactions. No performance tests are needed.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@sahar-fehri sahar-fehri added this pull request to the merge queue Jan 30, 2026
Merged via the queue into main with commit 58eab76 Jan 30, 2026
206 of 224 checks passed
@sahar-fehri sahar-fehri deleted the chore/add-trending-metrics branch January 30, 2026 16:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2026
@metamaskbot metamaskbot added the release-7.65.0 Issue or pull request that will be included in release 7.65.0 label Jan 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.65.0 Issue or pull request that will be included in release 7.65.0 size-XL team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants