Skip to content

Next.js websites cannot report page requests for server-side collection #34

Open

Description

@simpleanalytics-agent

What

Next.js websites should be able to report page requests for server-side collection with this package, instead of code written by a prompt (spec §11).

  1. A new function trackRequest for proxy.ts (middleware.ts before Next.js 16), separate from trackPageview.
  2. It does nothing until a setting is on. The setting is off by default. Its name is public and cannot change after release (spec §14.5).
  3. It sends the payload of spec §3 and the address headers of spec §4. It runs before the response exists, so it sends no status or content type, skips assets by path and also reports 404s.
  4. It never slows or breaks a page: it sends alongside the response, gives up after 2 seconds, never retries, swallows errors, and never sends cookies or authorization headers (spec §2).

Why

Next.js and Vercel run proxy code before the cache and for static files, so cached pages are counted there (spec §11.4). A package can be updated; prompt-written code cannot.

Notes

  • Agreed design: simpleanalytics/ide-config#22, sections 2, 3, 4, 11 and 14.5.
  • The package build lists an entry src/middleware/index.ts that does not exist.

Activity

  1. simpleanalytics-agent commented on Nov 18, 2026

    @simpleanalytics-agent
    Author

    Landed on feat/server-side-collection (2595701) in draft #35. This issue closes when that PR merges.

    What the code does now: trackRequest in @simpleanalytics/next/server 1.2.0 reports GET page requests from proxy.ts/middleware.ts with the v1 payload. It is off unless SIMPLE_ANALYTICS_SERVER_SIDE_COLLECTION=1 or serverSideCollection is set. Test mode is SIMPLE_ANALYTICS_TEST_MODE=1.

    • Validation: one round, passed. The review covered cookies and authorization, hostile query strings, uppercase asset extensions, a hanging queue, a queue answering 500, and each value of the setting. It ran on Next 15 and 16.
    • Numbers: 13 payload tests. Page response about 25 ms with the queue slow or down.
    • Open decisions: (a) the setting is an environment variable plus a per-call option; the alternatives are a per-call option only or a plugin option. (b) the names SIMPLE_ANALYTICS_SERVER_SIDE_COLLECTION and SIMPLE_ANALYTICS_TEST_MODE are permanent after release. (c) App Router navigations and prefetches are reported as page requests. (d) the stale src/middleware/index.ts tsup entry is left, as it does not block the build.
    • Not run: anything against the real queue, which does not have /requests yet.
    • Later: no workflow runs pnpm test before publishing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions