-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
29 lines (25 loc) · 1.14 KB
/
Copy pathproxy.ts
File metadata and controls
29 lines (25 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { NextResponse, type NextRequest } from "next/server"
import { ACQ_COOKIE, ACQ_COOKIE_MAX_AGE, acquisitionFromRequest } from "@/lib/acquisition"
// First-touch acquisition capture (lib/acquisition.ts): when a visitor arrives
// with utm params, ?src=, or an external referrer and has no acquisition cookie
// yet, record the channel + landing path. Signup reads the cookie and stamps it
// onto the Wallet so the funnel can tie channel → signup → first governed
// decision. First-touch-wins: an existing cookie is never overwritten.
export function proxy(req: NextRequest) {
if (req.cookies.has(ACQ_COOKIE)) return NextResponse.next()
const acq = acquisitionFromRequest(req.nextUrl, req.headers.get("referer"))
if (!acq) return NextResponse.next()
const res = NextResponse.next()
res.cookies.set(ACQ_COOKIE, JSON.stringify(acq), {
maxAge: ACQ_COOKIE_MAX_AGE,
httpOnly: true,
sameSite: "lax",
secure: process.env.NODE_ENV === "production",
path: "/",
})
return res
}
export const config = {
// Page routes only — not the API planes, Next internals, or static assets.
matcher: ["/((?!api|_next|brand|.*\\..*).*)"],
}