Repository navigation
fix(traffic): store an anonymous visitor key instead of the visitor's IP address - #1410
Merged
Merged
Conversation
… IP address The tracking snippet's route stored each AI-referred visitor's IP address in ai_traffic_logs. The address was only needed to group a visit's pageviews for half an hour and to find the pageview a not-found title belongs to. The route now stores a visitor key instead: a one-way hash of the IP address, the brand and a salt that changes every UTC day. The database makes each day's salt on first use and deletes it after two days (traffic_salt, 00250), so nothing links a key to an address once its salt is gone, and a visitor's days can't be joined. Visits and the not-found mark match on the key and the user agent, as they did on the address. If no key can be made, the pageview is stored as a visit of its own. 00250 also erases the IP addresses already stored. Their visits stay as they were grouped.
7 of 12 tasks
This was referenced Oct 23, 2026
Merged
8 of 12 tasks
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.
Summary
The tracking snippet's route stored each AI-referred visitor's IP address in
ai_traffic_logs.ip_address. The address was only needed for two things, both short-lived:What changes:
visitor_key: a one-way SHA-256 of the IP address, the brand and a salt that changes every UTC day (server/src/lib/visitor-key.js). The IP address itself is no longer written anywhere.traffic_salt(day)(00250) makes each day's salt on first use and deletes salts older than the day before. Once a salt is gone, nothing links its keys to an address. A visitor gets a new key every day, so their days can't be joined.traffic_daily_saltshas RLS on and no access foranonorauthenticated. The function isservice_roleonly.visit_ofwas decided when each pageview was stored.Docs. The AI Traffic guide's privacy section says this in #1408.
Related issue
None. Found while updating the AI Traffic guide (#1380): it said "anonymized IP", which wasn't so.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsDeploy order
update ai_traffic_logs set ip_address = null where ip_address is not null.How to test
visitor_keyand noip_address.Tests:
visitor-key.test.js: the same key all day, a new key the next day, for another brand or another address; no address inside the key; the salt read once a day.traffic-track.test.js: the row holds no IP address, and a failed key still stores the pageview.traffic-visits.test.js: matches on the key.Server:
npm run format && npm run lint && npm test(2,132 tests) pass.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no web changeyarn typecheckpasses (run fromweb/): no web changeyarn format:checkpasses (run fromweb/): no web change🤖 Generated with Claude Code