Click-fraud protection for Next.js
Install @spurn/next, drop the script component into your root layout, and add the proxy helper. Paid landings are checked in the browser and on the server, and nothing waits on Spurn.
Set up Next.js
npm package
- 1
Install the package
Add it to your app.
Terminal npm install @spurn/next - 2
Add the script
SpurnScript wraps next/script and loads the tag with your public key.
app/layout.tsx import { SpurnScript } from '@spurn/next' export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> {children} <SpurnScript siteKey="sp_pub_XXXXXXXX" /> </body> </html> ) } - 3
Check on the server
The proxy helper sends a server hit for paid landings using event.waitUntil, so the response is never held up.
proxy.ts import { spurnProxy } from '@spurn/next' // Sends a server hit for paid landings with event.waitUntil. // Never awaited on the response path. export const proxy = spurnProxy({ secretKey: process.env.SPURN_SECRET_KEY ?? '' }) - 4
Send conversions
Call trackConversion from server code when an order is paid.
Server code import { trackConversion } from '@spurn/next' await trackConversion({ secretKey: process.env.SPURN_SECRET_KEY ?? '', orderId: order.id, value: order.total, currency: 'USD', })
Stop paying for clicks that never shop
Start on the free plan: 1,000 paid clicks a month, no card. Paid plans begin with a 14-day trial.