Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Track a request in your Next.js middleware (now named proxy.ts):

```typescript
// proxy.ts
import { NextResponse, type NextRequest } from "next/server"
import { NextResponse, type NextRequest, after } from "next/server"
import { AgentAnalytics } from "@upstash/agent-analytics"
import { redis } from "./redis"

const analytics = new AgentAnalytics({ redis })

export const proxy = async (request: NextRequest) => {
await analytics.track(request)
after(() => analytics.track(request))

return NextResponse.next()
}
Expand Down
5 changes: 2 additions & 3 deletions src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ export class AgentAnalytics {
* applies to the event form and defaults to now.
*
* Returns a promise resolving to the counter's new value. In a request
* handler you usually don't want to block the response on it — hand it to the
* runtime's `waitUntil` instead (see the README for the Vercel/Next.js
* pattern).
* handler you usually don't want to block the response on it — schedule it
* with Next.js `after()` instead (see the README proxy example).
*
* Dimension order does not matter: `track({ provider, path })` and
* `track({ path, provider })` increment the same counter.
Expand Down