Is your 404 page mailing your links to Google?
🌱 seedlingplanted #analytics#privacy#web#lessons
Written for Anyone running a site with Google Analytics or another page-view counter, especially one that sends links by email.
I fixed this garden's 404 page this morning, so the story below is still warm.
The numbers come from the git history of the site described below, read on 3 and 4 December, and from a rerun on this garden. AI helped with the reading and the draft.
Tiếng Việt: Trang 404 của bạn có đang gửi link cho Google?.
Picture an address like this in the browser bar:
/huy-dang-ky/?t=8f3a…
It is an unsubscribe link, the kind at the bottom of every newsletter (the path is Vietnamese for "unsubscribe"). The ?t= part is one person's private token: whoever holds the link can cancel that person's mail. There is only one question: where does this address go?
Where the address goes
Any page with a Google Analytics tag sends its full address to Google. On every page view the GA4 tag sends a field called page_location, and by default that field is the whole URL, query string included. For an article that is fine. For a link with a token, the token sits in your reports, on someone else's server.
The 404 page is the worst place for a tag. Every other page has an address you chose. The 404 page gets exactly what people typed, pasted or clicked in an email: typos, old links, truncated links, links with a stray character. You cannot know in advance what it holds. Yet most web frameworks share one layout across all pages, the 404 included, so the tag comes along.
The first patch: list all four paths
I read this story in the git history of a site with a newsletter sign-up box. The box was still closed: no database, no mail ever sent.
On 1 December a legal review of that site wrote one line: while the sign-up is closed, a confirm or unsubscribe link returns the tagged 404, so the token in the link would reach GA4. The same line says plainly that no token had ever been issued. The hole was real, nobody had fallen in, and nothing leaked.
The first patch landed on the morning of 2 December. Four paths (confirm and unsubscribe, in two languages each) now returned a separate 404 with no tag. A test came with it: four paths times three token shapes (?t=x, an empty ?t=, no token), 12 cases, none with a tag. All green.
The thirteenth case
Twelve green cases, and the hole was still open. The next morning a review tried /huy-dang-ky/?t=x, with one extra / at the end. It got the tagged 404, and the token x went along to GA4.
The cause was the router. The site runs on Hono, and by default Hono matches paths character for character, so /huy-dang-ky/ does not match /huy-dang-ky. An address that matches no route falls through to the shared 404, the tagged one. The first patch guarded exactly the four doors it knew about. The address walked in through a fifth.
Every list works like that: however many paths you write down, there is one you did not think of. A trailing /, capital letters, a translation added next year.
The second patch: one 404, no tag
The right fix was the smaller one. Before it there were two 404 pages, one tagged and one not, and a tagged flag to pick between them. The second commit deleted the separate copy and the flag, and left one 404 page that never prints a tag: 7 lines added, 11 removed. The test grew to seven paths, adding the trailing-slash version and a path that does not exist, times three token shapes: 21 cases.
The lesson that site wrote down for next time has one idea: guard the whole class, not the paths you can list.
This garden just did the same. Its 404 page never carried a tag, but no test held it to that, and it lacked the page frame, so on a phone the text was tiny. Now it shares the layout with every other page, minus the tag, and a test reads it in both languages.
One curl line for your site
SITE=https://example.com
curl -s -A Mozilla/5.0 \
"$SITE/x/?t=abc" |
grep -c -e googletagmanager \
-e 'gtag(' -e plausible \
-e umami -e matomo
0 is what you want. Anything else means your 404 page carries a tag. Run on this garden today:
404 page (/khong-co/?t=abc) 0
home page (/) 4
The home page shows 4 because it really is tagged; the 404 shows 0. Two easy trips. First, quote the address: zsh treats ? as a wildcard, so unquoted the command dies before it runs, and a check here tripped on exactly that this week. Second, -A Mozilla/5.0 is there because this garden answers curl with a text version; on most sites you can drop it.
If you get something other than 0, the fix is usually short: find where the layout prints the tag, let the 404 page skip it, then write a test that reads the 404 at a made-up path and counts tags. The made-up path is the point: a test built on the paths you know repeats the first patch.
What I still don't know
The tag is only one way an address leaks. If the 404 page loads an image or a font from another server, the browser may send the address along in the Referer header, depending on the page's referrer policy. Your server logs keep the full address too. GA4 has a data-redaction setting for URL query parameters, but you have to name the parameters yourself, which is a list again, and I have not tried it. And where that stray / would come from in real life, a mail app, someone typing by hand or a link shortener, I don't know either: nobody has fallen into this hole, so there is nobody to ask.
Write papa dragon a letter
If this note stirred something, write to me here. A letter reaches only me and never shows up on the page by itself. If one is lovely and you allow it, I may quote it under the note, without your name.
Works from a terminal too: curl -d 'msg=…' olragon.com/garden/untagged-404-en/letter