Repository navigation
Preserve browser query attribution for manual pageviews - #109
simple-analytics-ai[bot] wants to merge 11 commits into
Conversation
Requested in the compatibility review: fix query-only manual pageview loss and preserve full path-overwriter input. Keep the filtered outgoing path and review campaign attribution separately. Refs #107
Requested in item 2: keep the previous browser-URL query behavior for pageviews and events. Remove the manual-query override while retaining case-insensitive filtering and the querykeys opt-out. Refs #107
Claude review checkpointReviewed commit |
|
SDLC label: |
Address automated review of item 1: normalize the manual query after the path-overwriter callback and before ignore-pages/hash handling, while keeping its query in the duplicate key. Refs #107
Carry the item 1 ignore-pages and hash fixes into the separate item 2 PR. Preserve browser-URL attribution while retaining only the manual query duplicate key and keeping payload paths filtered. Refs #107
Keep item 2 separately reviewable against the updated item 1 base after validating the combined source and generated bundles. Refs #107
|
Smallest fix: if (overwrite && isString(path)) path = path.split("?")[0];(The line arrives via the merged |
Address review of item 1: only split string path values, preserving numeric manual paths and numeric path-overwriter results without introducing an exception into the customer page. Refs #107
Carry the reviewed item 1 string guard and numeric regression into item 2 while preserving browser-URL attribution. Refs #107
Preserve the one-change review scope of item 2 against the updated item 1 base. The merged tree passed all 21 unit tests and the build. Refs #107
|
The numeric-path finding is addressed in the updated #108 base and merged into this branch at d3d6e56. Normalization only splits strings; numeric manual paths and numeric path-overwriter results remain accepted. All 21 unit tests pass. The PR diff against #108 remains limited to browser-query attribution. |
Requested during review: keep the existing path-overwriter behavior without query strings, while retaining distinct manual-query pageviews. Restore query splitting before getPath and update the callback and duplicate checks.
Carry the requested callback compatibility correction from PR #108 into its dependent attribution PR. Remove queries before getPath, preserve distinct-query duplicate detection, and regenerate the bundles. All 21 unit tests and both builds pass.
Preserve the requested existing path-overwriter behavior throughout the PR stack. Resolve generated bundle conflicts with the validated attribution tree; both builds, all 21 unit tests, formatting and diff checks pass.
Documentation update
|
|
Update to #109 (comment): PR #109 was closed without merging. I removed both of its proposed docs changes from the pending bundle, including the browser-query-only attribution copy. The earlier local draft is retired; nothing from it was published to the docs repository. |
|
Closing because the agreed contract is to use an explicitly supplied manual query, with existing filtering, and fall back to location.search only when no manual query is supplied. Removing overwriteSearch would undo that contract. Events continue to read their browser query independently. The current v12 implementation already preserves this behavior. |
Summary
Closes #107
Manual page views replaced the browser URL query with the manually supplied query, which lost landing-page attribution for the page view and for every event sent afterwards.
getQueryParams()now readslocation.searchagain instead of accepting anoverwriteSearchargument:The manually supplied pathname is still honoured. The query is stripped from
pathOverwritebeforegetPath()is called, somyPathOverwriterreceives{ path: "/product" }forsa_pageview("/product?product-id=1"), anddata-ignore-pages, hash routes, numeric paths and numeric path-overwriter results keep working. The manual query is kept only as part of the internallastSendPathkey (from #108) so that manual page views differing only in their query are not deduplicated; it is never sent to the API.Changes:
Security implications
Has security impact - described as: query attribution is read from the browser URL again and stays filtered through the UTM allowlist,
data-allow-paramsand thequerykeysopt-out, so a manually supplied query string can no longer place unfiltered URL parameters in the recorded path. The manual query is retained only as an in-memory deduplication key and is removed before the path callback runs.Testing
Run by Claude on Node 22.23.3:
npm run build: passed;dist/latest/latest.dev.jsis unchanged, so the committed build matchessrc/.npx mocha test/unit/*.test.js: 21 passing, covering browser-query attribution for page views and events, pathname-only path-overwriter input, distinct-query and identical-call handling, ignored paths, hash routes, and numeric paths/results.jsdomis not declared indevDependencies, so it had to be installed with--no-saveto run these tests.npx prettier --check src test: the only warning is the pre-existingtest/deploy.test.mts, which this PR does not touch.npx eslint src/*.js: passed.sa_pageview("/order?email=leak@example.com&token=abc")sendspath=/orderand no request (pixel or/appendbeacon) contains the manual query.Checklist