Repository navigation
feat(analytics): track route params on screen views - #180
devs-rootstrap wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The eyJ-only filter misses valid JWTs with whitespace-formatted headers, allowing credentials in permitted parameters such as state to reach every analytics adapter by default.
1 open issue
What changed in this PR
Overall Review: ai:serious
Extends the provider-agnostic analytics layer from #161 to include route parameters in automatic screen views while keeping screen names as route patterns.
Changes:
- Adds parameter normalization, sensitive-data filtering, and configurable parameter tracking.
- Reports new screen views when tracked parameters change, ignoring parameter-key order.
- Adds tests and documents the deliberate default, privacy limitations, and opt-out options.
| File | Description |
|---|---|
src/components/providers/analytics-tracking.ts |
Adds parameter filtering, tracking options, and parameter-aware change detection. |
docs/src/content/docs/guides/analytics.mdx |
Documents parameter tracking, privacy limitations, and configuration. |
__tests__/components/providers/analytics-tracking.test.tsx |
Adds coverage for normalization, filtering, tracking options, and change detection. |
Review effort: Balanced
| ]; | ||
|
|
||
| const EMAIL_VALUE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| const JWT_VALUE = /^eyJ[\w-]*\.[\w-]+\.[\w-]*$/; |
| ); | ||
| } | ||
|
|
||
| function isTrackableParam(key: string) { |
There was a problem hiding this comment.
@devs-rootstrap All screen params are trackable. There's not such a thing as sensitive data in a screen param, as they would only contain ids, modes, etc.
There was a problem hiding this comment.
@asdolo Done, all route params are now sent with screen views, with no filtering by name or value.
- 6a02409: removed the sensitive-name denylist (
SENSITIVE_PARAM_WORDSand helpers) and the email/JWT value checks fromanalytics-tracking.ts, dropped the tests that asserted params were filtered, and updated the analytics guide. The only param still excluded is expo-router's#URL fragment, since it isn't a route or search param. Repeated params are still joined with commas, nested objects are still dropped, and thetrackParamsoption (falseor a name filter) still works. - a08336b, d80e39e, ece4c92: the comment on
DEFAULT_TRACK_PARAMSand the docs now say that route params are non-sensitive by design. That includes params coming from deep links, so they should carry ids and modes only. Also added a test that a param rejected by atrackParamsfunction doesn't trigger a new screen view.
Lint, type-check, translations lint and the full test suite pass.
There was a problem hiding this comment.
@devs-rootstrap please keep an eye on Sonarqube.
There was a problem hiding this comment.
@asdolo The SonarQube quality gate was failing on this PR, on both earlier pushes, and it passes now on f018c27.
- d7350fa: the most likely cause was the plain
.sort()on the param names intoParamsKey. Sonar reports a sort with no compare function as a bug, and one new bug is enough to fail the gate. It now passes an explicit compare function. The order is the same as before (code unit order) and doesn't depend on the device locale. - f018c27: added tests for params that change and come back within the same tick, and for the order of param names. That covers the one line of new code without coverage, so
analytics-tracking.tsis now fully covered (lines and branches).
All route params are still sent, as agreed above. Lint, type-check, translations lint and the full test suite pass.

Follow-up to #161.
Jira board reference:
What does this do?
Adds automatic navigation params tracking to the screen views reported by
useAnalyticsScreenTracking(added in #161), as requested in #161.useGlobalSearchParams()and sends them as theparamsargument oftrackScreen. The screen name stays the route pattern, so/feed/42?tab=commentsis reported astrackScreen('/feed/[id]', { id: '42', tab: 'comments' }). Routes without params still sendundefined./feed/1→/feed/2) counts as a new screen view. The same params in a different order do not. The one-tick wait for launch redirects is unchanged.#...) is never sent.SENSITIVE_PARAM_WORDS:token,secret,password,code,otp,email,key,auth,session,client,uid,pin,phone, ...). Names are split on camelCase, acronyms,_,-and digits, and both plurals and compound words are matched (resetCode,access_token,apikey,emails,token2,tokenvalue). Names likeauthorandkeyboardare still sent.trackParamsoption onuseAnalyticsScreenTracking. It defaults totrue, which keeps the behavior above.falsesends no params. A function(name) => booleannarrows the params to an allowlist. The denylist still runs first, so the function can never re-enable a sensitive name.docs/src/content/docs/guides/analytics.mdx) documents the params, the denylist, the deliberate default and how to turn param tracking off or narrow it.Why did you do this?
#161 was asked to follow up by adding automatic navigation params tracking to
trackScreen. The maintainers chose to send route params by default and filter them with a denylist, rather than use an opt-in allowlist. The code (DEFAULT_TRACK_PARAMS) and the guide both say this is a deliberate default.trackParamslets apps whose routes carry sensitive data turn tracking off or narrow it without editing the hook.Who/what does this impact?
undefined. Adapters that ignoreparamsare not affected.router.setParamsreports a new screen view on each change.Layer 2: Risk Classification
risk:high: changes which data is sent to third-party analytics vendors by default.How did you test this?
Verification
pnpm lint,pnpm type-check,pnpm lint:translationsandpnpm test(40 suites, 249 tests) pass, as do the pre-push checks.__tests__/components/providers/analytics-tracking.test.tsxcovers params sent with the screen view, the denylist (names and email/JWT values, including repeated params), the default,trackParams: false, a narrowing function that cannot re-enable sensitive names, and change detection by params.To test locally
git fetch origin && git checkout feat/analytics-screen-params && pnpm installpnpm test __tests__/components/providers/analytics-tracking.test.tsx?tab=comments) and check theparamsargument passed totrackScreen.Notes:
ref,state) or an id in a dynamic segment is still sent, and the guide says so. Apps can narrow tracking withtrackParams, extendSENSITIVE_PARAM_WORDSor filter in their adapters.guidormonkey) are not sent either.