Skip to content

feat(analytics): track route params on screen views - #180

Open
devs-rootstrap wants to merge 14 commits into
masterfrom
feat/analytics-screen-params
Open

devs-rootstrap wants to merge 14 commits into
masterfrom
feat/analytics-screen-params

Conversation

@devs-rootstrap

Copy link
Copy Markdown
Collaborator

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.

  • The hook reads the focused route's params with useGlobalSearchParams() and sends them as the params argument of trackScreen. The screen name stays the route pattern, so /feed/42?tab=comments is reported as trackScreen('/feed/[id]', { id: '42', tab: 'comments' }). Routes without params still send undefined.
  • Values are sent as strings. Repeated params and catch-all segments are joined with commas, and object or empty values are dropped.
  • A change in params alone (/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.
  • Default: denylist. Every route param is sent unless it is filtered out:
    • The URL fragment (#...) is never sent.
    • A param is dropped when its name looks sensitive (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 like author and keyboard are still sent.
    • A value that looks like an email address or a JWT is dropped whatever the param is called, and each value of a repeated param is checked on its own.
  • New trackParams option on useAnalyticsScreenTracking. It defaults to true, which keeps the behavior above. false sends no params. A function (name) => boolean narrows the params to an allowlist. The denylist still runs first, so the function can never re-enable a sensitive name.
  • The analytics guide (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. trackParams lets apps whose routes carry sensitive data turn tracking off or narrow it without editing the hook.

Who/what does this impact?

  • Every analytics adapter now receives route params with each screen view, where it used to receive undefined. Adapters that ignore params are not affected.
  • Apps built from the template now send route param values (for example ids in dynamic segments) to their analytics vendors by default. The guide asks teams to review their routes and shows how to opt out.
  • Screen views are now counted per params change, so URL state updated with router.setParams reports 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?

  • Tested on iOS
  • Tested on Android
  • Tested on a small device
  • Tested on a real device
  • Tested all flows related with this PR changes
  • Tested accessibility
  • Added tests

Verification

  • pnpm lint, pnpm type-check, pnpm lint:translations and pnpm test (40 suites, 249 tests) pass, as do the pre-push checks.
  • __tests__/components/providers/analytics-tracking.test.tsx covers 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.
  • Not yet verified on a device or simulator.

To test locally

  1. git fetch origin && git checkout feat/analytics-screen-params && pnpm install
  2. pnpm test __tests__/components/providers/analytics-tracking.test.tsx
  3. Optionally register a logging adapter, open a screen with params (for example a deep link with ?tab=comments) and check the params argument passed to trackScreen.

Notes:

  • The denylist and the value checks are best effort. An opaque credential under an unrelated name (ref, state) or an id in a dynamic segment is still sent, and the guide says so. Apps can narrow tracking with trackParams, extend SENSITIVE_PARAM_WORDS or filter in their adapters.
  • Matching names by suffix or prefix errs on the side of dropping params, so a few harmless names (for example guid or monkey) are not sent either.

@devs-rootstrap
devs-rootstrap requested a review from a team as a code owner November 25, 2026 17:51
@devs-rootstrap devs-rootstrap added the risk:high Auth, payments, migrations, security-sensitive code. label Nov 25, 2026
@devs-rootstrap devs-rootstrap added the risk:high Auth, payments, migrations, security-sensitive code. label Nov 25, 2026
Copilot AI balanced review requested due to automatic review settings November 25, 2026 17:51
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

💯 Test Coverage

Lines Statements Branches Functions
Coverage: 66%
66.36% (509/767) 68.57% (251/366) 61.85% (193/312)

😎 Tests Results

Tests Skipped Failures Errors Time
249 0 💤 0 ❌ 0 🔥 39.861s ⏱️
👀 Tests Details • (66%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files66.3668.5761.8566.71 
report-only-changed-files is enabled. No files were changed in this commit :)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@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_WORDS and helpers) and the email/JWT value checks from analytics-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 the trackParams option (false or a name filter) still works.
  • a08336b, d80e39e, ece4c92: the comment on DEFAULT_TRACK_PARAMS and 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 a trackParams function doesn't trigger a new screen view.

Lint, type-check, translations lint and the full test suite pass.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@devs-rootstrap please keep an eye on Sonarqube.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@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 in toParamsKey. 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.ts is 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.

@asdolo asdolo added the ai:serious Security concerns, logic errors label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:serious Security concerns, logic errors risk:high Auth, payments, migrations, security-sensitive code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants