Skip to Content
SnapVibrSnapVibrDocs
Integrations

Next.js & React (next-agent-ready)

Install and configure next-agent-ready middleware for Next.js App Router and Pages Router applications.

Next.js and React (next-agent-ready)

For Next.js (App Router and Pages Router) and React applications, SnapVibr provides the next-agent-ready npm package to serve clean semantic HTML to AI crawlers at the middleware layer.

1. Install the Package

npm install next-agent-ready

2. Add Environment Variables

Copy your SNAPVIBR_SITE_ID and SNAPVIBR_API_KEY from Dashboard > AI Visibility > Edge Deployment and add them to .env.local (and your hosting provider's environment settings):

SNAPVIBR_SITE_ID=your_site_id
SNAPVIBR_API_KEY=your_api_key

3. Configure Next.js Middleware

Create or update src/middleware.ts (or middleware.ts at your project root):

import { createAgentReadyMiddleware } from 'next-agent-ready/middleware';

export const middleware = createAgentReadyMiddleware({
  domain: 'yourdomain.com',
  siteId: process.env.SNAPVIBR_SITE_ID,
  snapvibrApiKey: process.env.SNAPVIBR_API_KEY,
  autoFetchRemoteGrounding: true,
});

export default middleware;

export const config = {
  matcher: [
    '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
  ],
};

Standard browser traffic passes directly through to your Next.js routes without modification, while AI search crawlers receive clean semantic HTML with your live Brand Grounding context.

4. Verify in SnapVibr

After deploying your Next.js app, open Dashboard > AI Visibility > AI Page Preview / Validator and run a simulated crawler check against your production URL.

On this page