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

@devs-rootstrap devs-rootstrap commented Nov 25, 2026 •

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.
  • Every route param is sent by default, with no filtering by name or value. Route params are treated as non-sensitive by design (ids, modes and similar values), as agreed in review. The only param left out is expo-router's # URL fragment, which is not a route or search param.
  • 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 (names are sorted with an explicit, locale-independent compare function). The one-tick wait for launch redirects is unchanged.
  • New trackParams option on useAnalyticsScreenTracking. It defaults to true (send every param). false sends no params, and a function (name) => boolean narrows the params to an allowlist. A param rejected by the function does not trigger a new screen view.
  • The comment on DEFAULT_TRACK_PARAMS and 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. trackParams remains for apps that want to turn tracking off or send only some params.

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 all route param values (for example ids in dynamic segments and search params) to their analytics vendors by default. Apps must keep credentials and personal data out of route params, or pass trackParams: false or an allowlist function.
  • 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 pass, as do the pre-push checks. The SonarQube quality gate passes.
  • __tests__/components/providers/analytics-tracking.test.tsx covers 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.
  • 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:

  • There is no redaction: if an app passes a token or personal data as a route param, it is sent to the analytics vendors. This trade-off was accepted in review and is stated in the code and the guide.

@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

@fernandatoledo fernandatoledo left a comment

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.

Looks good, @devs-rootstrap please tackle @asdolo comments first

Comment on lines +27 to +39
/**
* 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.
*/

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 can you update the pr description given your last changes?

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.

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

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.

5 participants