From 308292ebf922125955e894436d2b03e2ffa5164c Mon Sep 17 00:00:00 2001 From: "Dominik K." Date: Thu, 4 Jun 2026 22:38:38 +0200 Subject: [PATCH] docs: use after for analytics proxy Uses after for the analytics tracking as recommended by Next.js https://nextjs.org/docs/app/api-reference/functions/after --- README.md | 4 ++-- src/analytics.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9f81676..1de42b0 100644 --- a/README.md +++ b/README.md @@ -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() } diff --git a/src/analytics.ts b/src/analytics.ts index 763cea4..21f5fbd 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -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.