OutboundIQ SDK for Next.js - Automatic tracking of all outbound API calls
npm install @outbound_iq/nextjsNext.js integration for OutboundIQ - Third-party API monitoring and analytics.
``bash`
npm install @outboundiq/nextjs
`env`
OUTBOUNDIQ_KEY=your-api-key
Create instrumentation.ts in your project root:
`typescript`
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('@outboundiq/nextjs/register');
}
}
`javascript
// next.config.js
const nextConfig = {
experimental: {
instrumentationHook: true,
},
};
module.exports = nextConfig;
`
Done! All outbound API calls are now automatically tracked.
`bashRequired - your API key from OutboundIQ dashboard
OUTBOUNDIQ_KEY=your-api-key
User Context (Optional)
Track which user made each API call:
`typescript
// middleware.ts
import { withOutboundIQ } from '@outboundiq/nextjs/middleware';
import { NextResponse } from 'next/server';export default withOutboundIQ(async (request) => {
return NextResponse.next();
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};
`$3
`typescript
import { withOutboundIQ } from '@outboundiq/nextjs/middleware';
import { getToken } from 'next-auth/jwt';export default withOutboundIQ(async (request) => {
return NextResponse.next();
}, {
getUserContext: async (request) => {
const token = await getToken({ req: request });
return token ? {
userId: token.sub,
context: 'authenticated',
} : null;
},
});
``All outbound HTTP requests from:
- ✅ Server Components
- ✅ API Routes
- ✅ Server Actions
- ✅ Route Handlers
Not tracked:
- ❌ Client-side browser requests (intentional)
- ❌ Requests to OutboundIQ itself
MIT