Skip to content

chore: update AI insights tracking#27851

Merged
joaosantos15 merged 14 commits into
mainfrom
TSA-299-track-ai-asset-symbol
Mar 26, 2026
Merged

chore: update AI insights tracking#27851
joaosantos15 merged 14 commits into
mainfrom
TSA-299-track-ai-asset-symbol

Conversation

@joaosantos15

@joaosantos15 joaosantos15 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Description

Adds asset_symbol property to the following tracking events:

Market Insights Clicked
Market Insights Viewed
Market Insights Interaction

Adds Market Insights Card Scrolled to View event.

This is necessary to make it easier to identify the assets in Mixpanel.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

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
Mostly analytics/tracing changes, but it alters useMarketInsights state reset behavior and gates MARKET_INSIGHTS_VIEWED emission on reportAssetId, which could affect when the Market Insights screen renders/tracks during fast asset switches.

Overview
Adds richer Market Insights analytics by attaching asset_symbol and API digest_id to MARKET_INSIGHTS_OPENED, MARKET_INSIGHTS_VIEWED, and MARKET_INSIGHTS_INTERACTION across token and perps entry points.

Introduces a new MARKET_INSIGHTS_CARD_SCROLLED_TO_VIEW event fired when the entry card becomes visible, and enhances useViewportTracking with measureInWindow-based polling plus a new Sentry trace (MarketInsightsViewportTracking) that records measure_calls and whether it resolved via visibility vs unmount.

Updates useMarketInsights to expose reportAssetId and to clear report/reportAssetId on (re)fetch; MarketInsightsView now avoids sending VIEWED analytics for stale reports when assetIdentifier changes before fresh data arrives. Also bumps @metamask/ai-controllers to ^0.6.0 and updates tests accordingly.

Written by Cursor Bugbot for commit 8bd8607. 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-social-ai Social & AI team label Mar 24, 2026
@joaosantos15 joaosantos15 added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Mar 24, 2026
@joaosantos15 joaosantos15 marked this pull request as ready for review March 24, 2026 10:57
@joaosantos15 joaosantos15 requested review from a team as code owners March 24, 2026 10:57
zone-live
zone-live previously approved these changes Mar 24, 2026
@github-actions github-actions Bot added the risk-low Low testing needed · Low bug introduction risk label Mar 25, 2026
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This PR adds a segment event to track when the Market Insights card
comes into view. This is necessary because at the moment it always
renders below the fold, making it arduous to get good CTR data for the
Market Insights feature. This adds a useful, intermediate step in the
funnel.


https://github.com/user-attachments/assets/f6267a60-300d-4aaf-831e-970af5f43743




<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Changelog**

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry: null

## **Related issues**

Fixes:

## **Manual testing steps**

```gherkin
Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]
```

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/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]
> **Medium Risk**
> Adds a new visibility-detection hook that uses a 250ms polling
interval until the card is visible, which could impact performance or
battery if misapplied. Other changes are additive analytics property
updates with low functional risk.
> 
> **Overview**
> Adds a new `MARKET_INSIGHTS_CARD_SCROLLED_TO_VIEW` analytics event
that fires once when the Market Insights entry card becomes at least 50%
visible, using a new `useViewportTracking` hook (layout + short polling)
and wiring it into `MarketInsightsEntryCard`.
> 
> Extends Market Insights telemetry to include `asset_symbol` on
`MARKET_INSIGHTS_OPENED`, `MARKET_INSIGHTS_VIEWED`, and
`MARKET_INSIGHTS_INTERACTION` events (token + perps contexts), with
updated unit tests to assert the new properties and event emission.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4407c73. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@joaosantos15 joaosantos15 changed the title chore: adds asset_name property to tracking event chore: update AI insights tracking Mar 25, 2026
@github-actions github-actions Bot added size-M risk-low Low testing needed · Low bug introduction risk and removed size-S risk-low Low testing needed · Low bug introduction risk labels Mar 25, 2026
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 25, 2026
zone-live
zone-live previously approved these changes Mar 25, 2026
@joaosantos15 joaosantos15 enabled auto-merge March 25, 2026 10:32
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 25, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 25, 2026
@joaosantos15 joaosantos15 enabled auto-merge March 25, 2026 18:54
Comment thread app/components/UI/MarketInsights/hooks/useViewportTracking.ts
zone-live
zone-live previously approved these changes Mar 25, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.75362% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.60%. Comparing base (62f6136) to head (2a340c9).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
...nts/UI/MarketInsights/hooks/useViewportTracking.ts 88.88% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27851      +/-   ##
==========================================
+ Coverage   82.56%   82.60%   +0.03%     
==========================================
  Files        4825     4837      +12     
  Lines      123955   124392     +437     
  Branches    27617    27730     +113     
==========================================
+ Hits       102346   102753     +407     
- Misses      14560    14575      +15     
- Partials     7049     7064      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zone-live zone-live dismissed stale reviews from Prithpal-Sooriya and themself via e6c286a March 25, 2026 20:28
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 25, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeTrade, SmokeWalletPlatform, SmokeCard, SmokePerps, SmokeRamps, SmokeMultiChainAPI, SmokePredictions, FlaskBuildTests
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/ai-controllers. Running all tests.

Performance Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/ai-controllers. Running all tests.

View GitHub Actions results

@cursor cursor Bot left a comment

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.

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

Fix All in Cursor

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

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@joaosantos15 joaosantos15 added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit 6e7ce9b Mar 26, 2026
216 of 253 checks passed
@joaosantos15 joaosantos15 deleted the TSA-299-track-ai-asset-symbol branch March 26, 2026 09:10
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-high Extensive testing required · High bug introduction risk size-L team-social-ai Social & AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants