1. Drop the 3.9 KB single-line SDK into app/layout.tsx
Add the site-scoped bundle inside your root `<head>` (or via `next/script` with `strategy="afterInteractive"`). Using `data-release` tags frontend JS exceptions by commit or semver version.
import Script from 'next/script';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://prismuv.com/s/YOUR_SITE_ID/prismuv.js"
strategy="afterInteractive"
data-release={process.env.NEXT_PUBLIC_RELEASE || 'v1.0.0'}
/>
</body>
</html>
);
}2. Track AI & Search crawlers with non-blocking middleware.ts
Because OAI-SearchBot and Claude-SearchBot often parse raw SSR HTML without firing analytics JS, detect their User-Agent in Edge/Node middleware and dispatch `event.waitUntil()` to `/t/edge` with zero added TTFB latency.
import { NextResponse, type NextFetchEvent, type NextRequest } from 'next/server';
const AI_CRAWLERS = [
'oai-searchbot', 'chatgpt-user', 'gptbot',
'claudebot', 'claude-searchbot', 'claude-user',
'perplexitybot', 'googlebot', 'bingbot',
];
export function middleware(request: NextRequest, event: NextFetchEvent) {
const ua = request.headers.get('user-agent') || '';
if (ua && AI_CRAWLERS.some((t) => ua.toLowerCase().includes(t))) {
event.waitUntil(
fetch('https://prismuv.com/t/edge', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Prism-Edge-Secret': process.env.PRISMUV_EDGE_SECRET || '',
},
body: JSON.stringify({
site_id: 'YOUR_SITE_ID',
path: request.nextUrl.pathname || '/',
status_code: 200,
ua: ua.slice(0, 300),
}),
}).catch(() => {})
);
}
return NextResponse.next();
}
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon\.).*)'],
};3. Allow PrismUV in Content-Security-Policy (if strict CSP is enabled)
If your Next.js headers or Nginx gateway enforce Content-Security-Policy directives, permit `https://prismuv.com` inside `script-src` and `connect-src` (or skip third-party CSP entirely by using our `/_t/*` first-party proxy pattern).
// CSP directives when loading directly from prismuv.com: script-src 'self' https://prismuv.com; connect-src 'self' https://prismuv.com;