Skip to content

Commit

Permalink
Filter out amplitude cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhhd committed Jan 15, 2025
1 parent d1a93ca commit 75273b4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ function addSessionIdHeader(requestHeaders: Headers) {
requestHeaders.set(SESSION_ID_TAG, getSessionId());
}

function filterAmplitudeCookies(requestHeaders: Headers) {
const cookies: string | null = requestHeaders.get("cookie");
if (cookies) {
const filteredCookies = cookies
.split(";")
.filter((cookie: string) => !cookie.trim().startsWith("AMP_"))
.join("; ");
requestHeaders.set("cookie", filteredCookies);
}
}

const PUBLIC_FILE = /\.(.*)$/;

// Due to limitations in the edge runtime, we can't use the prom-client library to track metrics directly here.
Expand Down Expand Up @@ -87,6 +98,7 @@ export function middleware(request: NextRequest) {

addCallIdHeader(requestHeaders);
addSessionIdHeader(requestHeaders);
filterAmplitudeCookies(requestHeaders);

const response = NextResponse.next({
request: {
Expand Down

0 comments on commit 75273b4

Please sign in to comment.