Commit 4372187
authored
fix: add useBuildPortfolioUrl hook for centralized metrics tracking (MetaMask#22683)
## **Description**
### Problem
We are asking the user to opt into metrics/marketing twice, first time
is when the user installs the app, and the second time when the user
opens the web browser within the app. We have query params being passed
into Portfolio called `marketingEnabled` and `metricsEnabled` which
SHOULD opt in the user's tracking preferences thus dismissing the second
opt-in modal. The issue is that we are inconsistently passing these
params into various entry points
### Solution
Pass in the opted in metrics from mobile into the portfolio web app via
query params. Created a new `useBuildPortfolioUrl` hook that
automatically includes `marketingEnabled` and `metricsEnabled` query
parameters when building Portfolio URLs. This centralizes the logic for
including user consent preferences and ensures consistency across the
app.
### Changes
New Hook
- Created `app/components/hooks/useBuildPortfolioUrl.ts`
- Subscribes to `isDataCollectionForMarketingEnabled` from Redux state
- Subscribes to `metricsEnabled` from the `useMetrics` hook
- Returns a memoized function that builds Portfolio URLs with consent
parameters automatically
included
- Supports additional parameters via the second argument
- Updated all Portfolio URL entry points to use new hook
Before:
```typescript
const isDataCollectionForMarketingEnabled = useSelector(
(state) => state.security.dataCollectionForMarketing,
);
const { isEnabled } = useMetrics();
const portfolioUrl = buildPortfolioUrl(
AppConstants.PORTFOLIO.URL,
{
marketingEnabled: isDataCollectionForMarketingEnabled ?? false,
metricsEnabled: isEnabled(),
srcChain: chainId,
},
);
```
After:
```typescript
const buildPortfolioUrlWithMetrics = useBuildPortfolioUrl();
const portfolioUrl = buildPortfolioUrlWithMetrics(
AppConstants.PORTFOLIO.URL,
{ srcChain: chainId },
);
```
## **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: Improved Portfolio integration by passing tracking
consent from Mobile app
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-45
## **Manual testing steps**
```gherkin
Feature: Portfolio tracking consent parameter
Scenario: user with no tracking preference opens Portfolio
Given user has not set tracking preference in app settings
When user taps the Portfolio link from wallet home screen
Then Portfolio URL should not include `marketingEnabled` and `metricsEnabled` parameter
And Portfolio website should display the consent modal
Scenario: user who accepted tracking opens Portfolio
Given user has accepted tracking in app settings
When user taps the Portfolio link from wallet home screen
Then Portfolio URL should include `marketingEnabled` and `metricsEnabled` as true
And Portfolio website should skip the consent modal
Scenario: user who declined tracking opens Portfolio
Given user has declined tracking in app settings
When user taps the Portfolio link from wallet home screen
Then Portfolio URL should include `marketingEnabled` and `metricsEnabled` as false
And Portfolio website should skip the consent modal
Scenario: user opens Portfolio Bridge with tracking consent
Given user has accepted tracking in app settings
When user taps "Bridge" from token asset options
Then Portfolio Bridge URL should include `marketingEnabled` and `metricsEnabled` is true
And Portfolio Bridge URL should include srcChain and token parameters
```
## **Screenshots/Recordings**
`~`
### **Before**
https://github.com/user-attachments/assets/4cdcdbec-0ffc-4b36-827e-eb442316eb33
### **After**
#### No Tracking Accepted
https://github.com/user-attachments/assets/58b4ec4b-6fcd-4d52-9f84-f3c4e8de9720
#### Tracking Accepted
https://github.com/user-attachments/assets/60921b12-87eb-40bb-9561-135d7e16742e
## **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**
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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]
> Adds a reusable hook and util to append metrics/marketing consent
params to Portfolio URLs and updates Portfolio, Bridge, Stake, Browser,
Trending, and AssetOptions flows to use it, with tests.
>
> - **Hooks/Utils**:
> - Add `useBuildPortfolioUrl` to auto-include `marketingEnabled` and
`metricsEnabled` when building Portfolio URLs.
> - Add `buildPortfolioUrl` in `util/browser` to append standard params;
deprecates scattered `appendURLParams` usage for Portfolio.
> - **UI Integrations**:
> - Update `AccountOverview` to build Portfolio URL with consent and map
`security.dataCollectionForMarketing` to props.
> - Update Bridge navigation (`useGoToPortfolioBridge`) to use hook and
include `srcChain`/`token`.
> - Update `StakeButton` to open Stake via hook-built URL when
ineligible.
> - Update `AssetOptions` Portfolio navigation to use hook.
> - Update `Browser` homepage URL generation to use hook.
> - Update `TrendingView` to use hook for browser button navigation.
> - Export `SectionHeaderProps` interface.
> - **Tests**:
> - Add tests for `useBuildPortfolioUrl` and `buildPortfolioUrl`.
> - Update `StakeButton` and `TrendingView` tests to reflect new URL
params.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
57608da. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 25288a6 commit 4372187
13 files changed
Lines changed: 381 additions & 55 deletions
File tree
- app
- components
- UI
- AccountOverview
- Bridge/hooks
- Stake/components/StakeButton
- Views
- AssetOptions
- Browser
- TrendingView
- components/SectionHeader
- hooks
- util/browser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
| |||
301 | 306 | | |
302 | 307 | | |
303 | 308 | | |
304 | | - | |
| 309 | + | |
305 | 310 | | |
306 | 311 | | |
307 | 312 | | |
| |||
310 | 315 | | |
311 | 316 | | |
312 | 317 | | |
313 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
314 | 328 | | |
315 | 329 | | |
316 | 330 | | |
| |||
440 | 454 | | |
441 | 455 | | |
442 | 456 | | |
| 457 | + | |
| 458 | + | |
443 | 459 | | |
444 | 460 | | |
445 | 461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| |||
256 | 266 | | |
257 | 267 | | |
258 | 268 | | |
259 | | - | |
| 269 | + | |
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 111 | | |
116 | 112 | | |
117 | 113 | | |
118 | 114 | | |
| 115 | + | |
119 | 116 | | |
120 | 117 | | |
121 | 118 | | |
| |||
166 | 163 | | |
167 | 164 | | |
168 | 165 | | |
169 | | - | |
| 166 | + | |
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
| |||
248 | 245 | | |
249 | 246 | | |
250 | 247 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
258 | 251 | | |
259 | 252 | | |
260 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
| 44 | + | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
78 | 76 | | |
79 | 77 | | |
80 | 78 | | |
81 | | - | |
| 79 | + | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
| |||
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 90 | | |
96 | 91 | | |
| 92 | + | |
| 93 | + | |
97 | 94 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 95 | + | |
| 96 | + | |
104 | 97 | | |
105 | 98 | | |
106 | 99 | | |
| |||
120 | 113 | | |
121 | 114 | | |
122 | 115 | | |
123 | | - | |
124 | 116 | | |
125 | 117 | | |
126 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
| 39 | + | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 53 | + | |
58 | 54 | | |
59 | 55 | | |
60 | 56 | | |
61 | 57 | | |
62 | | - | |
63 | 58 | | |
64 | 59 | | |
65 | 60 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 61 | | |
74 | 62 | | |
75 | 63 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
0 commit comments