Repository navigation
Report page requests for server-side collection with trackRequest - #35
Open
simpleanalytics-agent wants to merge 7 commits into
Open
simpleanalytics-agent wants to merge 7 commits into
simpleanalytics-agent wants to merge 7 commits into
Conversation
trackRequest runs in proxy.ts (middleware.ts before Next.js 16) and sends each GET page request to the queue's /requests route in the version 1 payload, so the queue can count AI agents and robots that never run the script. Assets are skipped by path; copied request headers travel in the body and address headers pass on under their own names. Cookies and authorization headers are never sent. It stays off until SIMPLE_ANALYTICS_SERVER_SIDE_COLLECTION (or the serverSideCollection option) is on, gives up after 2 seconds, never retries and never throws. Test mode (SIMPLE_ANALYTICS_TEST_MODE or testMode) sends test: true and prints the queue's reply on the server console. Adds node --test coverage for the payload and bumps the package to 1.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node.js 22 before 22.18 strips TypeScript types only with a flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
2 of 3 tasks
Each options shape has one consumer, and the package exports functions, not options types, like trackPageview and trackEvent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README and the documentation page start with a prompt that points the coding agent at the server-side collection guide, then manual setup. The README keeps a short quickstart and links the documentation page for what it reports, the options and test mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simpleanalytics-agent
marked this pull request as ready for review
November 18, 2026 19:54
This branch has not been deployed
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
Closes #34
Part of the server-side collection design in simpleanalytics/ide-config#22 (§11). AI agents and most robots do not run the script. Next.js websites can now report page requests from
proxy.ts(middleware.tsbefore Next.js 16) with a newtrackRequestfrom@simpleanalytics/next/server. It is separate fromtrackPageview, and the package goes to 1.2.0.SIMPLE_ANALYTICS_SERVER_SIDE_COLLECTION=1turns it on, orserverSideCollectionper call. Both names become permanent once 1.2.0 is on npm.https://queue.simpleanalyticscdn.com/requests. The copied request headers go in the body;X-Forwarded-Forand platform headers such asCF-Connecting-IPandTrue-Client-IPgo on the request. There is no status or content type, because proxy code runs before the response./_next/and Pages Router data requests. It never sends cookies or authorization headers, gives up after 2 seconds, never retries and swallows errors.SIMPLE_ANALYTICS_TEST_MODE=1(ortestMode) addstest: trueand prints the payload and the queue's reply on the server console./docs/server-side-collection), labelled beta. Both start with a prompt for an AI agent that points at the guide for coding agents, then manual setup.Tickets in this branch:
trackRequest)Merge last. Every push to
mainpublishes to npm. Merge only once the queue's/requestsroute (simpleanalytics/queue#116) and the Traefik change (simpleanalytics/infrastructure#367) are live.Accepted gaps: App Router client navigations and prefetches reach
proxy.tswithout any marker, so they are reported as page requests (the queue discards people). Next gives proxy code no socket address, soX-Forwarded-Foris passed on exactly as Next hands it over.Security implications
Testing
pnpm test: 13node --testcases for payload building, on Node 22.11, 24.13 and 24.22. Type check,pnpm build:package, the docs build and Prettier pass.middleware.ts) and Next 16.4.6 (Nodeproxy.ts) against a local stand-in for the queue: blocked parameters dropped, cookies and authorization never sent, 404s reported, assets and POST skipped. The page answered in about 25 ms with the queue delayed 5 seconds or down.Summary by CodeRabbit