Background
⌘K

Next.js Integration

Learn how to integrate Affonso affiliate tracking into your Next.js application using App Router.

Silvestro
Written by Silvestro
Updated more than a month ago

Follow these steps to add Affonso affiliate tracking to your Next.js App Router application using the recommended Script component approach.

Add Tracking Script to Root Layout

Add the Affonso tracking script to your root layout file at app/layout.tsx:

import Script from 'next/script';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang='en'>
      <head>
        <Script
          async
          defer
          src='https://affonso.io/js/pixel.min.js'
          data-affonso='YOUR_PUBLIC_PROGRAM_ID'
          data-cookie_duration='30'
          strategy='afterInteractive'
        />
      </head>
      <body>{children}</body>
    </html>
  );
}

Find your Program ID →

Next Steps

Once installed, you can access affiliate referral data and pass it to your payment provider. Learn how to integrate with your payment provider →

Testing

  1. Start your development server: npm run dev
  2. Visit localhost:3000?atp=test
  3. Check browser DevTools → ApplicationCookiesaffonso_referral
  4. Deploy and verify tracking in your Affonso dashboard

Note: Tracking is disabled on localhost to avoid false data.

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.