Repository navigation
Strip tracking parameters from redirect suggestions - #30
Merged
Merged
Conversation
Redirect targets often carry parameters that identify the visit rather than the content. support.google.com sends back a visit_id session token and an rd redirect counter, so a suggestion would have committed a value that is stale the moment it is applied. Known session, campaign, and click parameters are now removed from the suggested URL. A parameter the author already had on the link survives, since the point is to drop server noise, not rewrite intent. When stripping leaves the destination equal to the original link, the redirect carried nothing but tracking and no suggestion is made.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #29, which surfaced this.
Problem
Redirect targets often carry query parameters that identify the visit rather than the content.
support.google.comis the case that prompted this: following a redirect there lands on a URL carrying avisit_idsession token and anrdredirect counter.HyperHawk suggested that URL verbatim, so applying the one-click suggestion committed something like this into a markdown file:
The
visit_idis stale the moment it is written down. The path change is the real fix, the parameters are noise.This weakness predates #29, but #29 made it reachable for hosts that error on HEAD, so it would have started showing up more often.
Fix
buildRedirectUrlnow runs the destination throughstripTrackingParamsbefore re-attaching the fragment. Three rules:visit_id,rd,sjid,gclid/dclid/fbclid/msclkid,mc_cid/mc_eid,_ga/_gl, and anything prefixedutm_.isSameUrlsuppresses the suggestion rather than offering a no-op.Rule 3 was not in the original scope but falls out of the same problem.
example.com/xredirecting toexample.com/x?visit_id=...was pure noise before, and once the parameter is stripped there is nothing left to suggest.Verification
Against the real URL from the #29 follow-up:
support.google.com/analytics/answer/9143382.../table/13948007?visit_id=6392...&rd=2.../table/13948007support.google.com/analytics/answer/11109416Four new routes on the snapshot test server, one per rule plus the interaction with fragments:
/tracked-move-> /final, path move with all three parameters stripped/tracking-onlyok, no suggestion/keeps-author-param?utm_source=author-> /final?utm_source=author, author's parameter kept,visit_iddropped/tracked-move#my-anchor-> /final#my-anchor, fragment survives strippingThe existing
/finalroute had to widen from an exact string match to also match/final?..., since it would otherwise 404 once redirects started carrying query strings.npm run typecheckandnpm run test:snapshotpass.dist/is rebuilt and verified in sync withsrc/.Docs
docs/how-it-works.mdis updated in both places that describe redirect suggestions.