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.
fernandatoledo
left a comment
There was a problem hiding this comment.
Looks good, @devs-rootstrap please tackle @asdolo comments first
| /** | ||
| * Default decided by the template maintainers: every route param is sent with | ||
| * screen views, with no filtering by name or value. Route params are treated | ||
| * as non-sensitive by design: they only carry ids, modes and similar values. | ||
| * Tokens, codes and personal data must never be passed as route params (keep | ||
| * them in secure storage or request bodies instead). This includes incoming | ||
| * deep links: the app defines its own link routes, so they must carry ids | ||
| * only. A name or value denylist was used before and intentionally removed, | ||
| * since it could never be complete and gave a false sense of safety; the | ||
| * trade-off (no redaction when an app breaks this rule) is accepted. Apps | ||
| * whose links carry credentials pass `trackParams: false` or an allowlist | ||
| * function. | ||
| */ |
There was a problem hiding this comment.
@devs-rootstrap can you update the pr description given your last changes?
There was a problem hiding this comment.
@fernandatoledo Done, the description now matches the current state of the branch (up to f018c27): it says that every route param is sent with no name or value filtering (only the # fragment is left out), describes the trackParams option as it works now, removes the denylist and email/JWT sections and the notes about them, and mentions the explicit sort compare function and the new tests. No code changed. @asdolo's comments were already addressed in 6a02409, a08336b, d80e39e, ece4c92 (params unfiltered) and d7350fa, f018c27 (SonarQube gate, which passes now).

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.#URL fragment, which is not a route or search param./feed/1→/feed/2) counts as a new screen view. The same params in a different order do not (names are sorted with an explicit, locale-independent compare function). The one-tick wait for launch redirects is unchanged.trackParamsoption onuseAnalyticsScreenTracking. It defaults totrue(send every param).falsesends no params, and a function(name) => booleannarrows the params to an allowlist. A param rejected by the function does not trigger a new screen view.DEFAULT_TRACK_PARAMSand the analytics guide (docs/src/content/docs/guides/analytics.mdx) document the default, the rule that tokens, codes and personal data must never be passed as route params (including deep links), 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. An earlier version of this PR filtered params with a name denylist and email/JWT value checks; in review it was decided that screen params never carry sensitive data, so the filtering was removed and every param is sent.trackParamsremains for apps that want to turn tracking off or send only some params.Who/what does this impact?
undefined. Adapters that ignoreparamsare not affected.trackParams: falseor an allowlist function.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 testpass, as do the pre-push checks. The SonarQube quality gate passes.__tests__/components/providers/analytics-tracking.test.tsxcovers params sent with the screen view (including deep links), the#fragment being left out, repeated and non-primitive values, the default,trackParams: false, an allowlist function (and params it ignores not triggering a new screen view), change detection by params, params that change and come back within the same tick, and param name order.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: