Background
⌘K

Nuxt.js Integration

Learn how to integrate Affonso affiliate tracking into your Nuxt.js application.

Silvestro
Written by Silvestro
Updated more than a month ago

Nuxt.js Integration

Implement Affonso tracking in your Nuxt.js 3+ application with these methods designed for SSR, static generation, and client-side hydration.

Create or update your app.html file in the root directory:

<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
  <head {{ HEAD_ATTRS }}>
    {{ HEAD }}
    <script
      async
      defer
      src="https://affonso.io/js/pixel.min.js"
      data-affonso="YOUR_PUBLIC_PROGRAM_ID"
      data-cookie_duration="30"
    ></script>
  </head>
  <body {{ BODY_ATTRS }}>
    {{ APP }}
  </body>
</html>

Method 2: Nuxt Config

Add the script via nuxt.config.ts:

export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          async: true,
          defer: true,
          src: 'https://affonso.io/js/pixel.min.js',
          'data-affonso': 'YOUR_PUBLIC_PROGRAM_ID',
          'data-cookie_duration': '30',
        },
      ],
    },
  },
});

Method 3: Plugin (Dynamic Loading)

Create a plugin at plugins/affonso.client.ts:

export default defineNuxtPlugin(() => {
  if (process.client) {
    const script = document.createElement('script');
    script.async = true;
    script.defer = true;
    script.setAttribute('data-affonso', 'YOUR_PUBLIC_PROGRAM_ID');
    script.setAttribute('data-cookie_duration', '30');
    script.src = 'https://affonso.io/js/pixel.min.js';
    document.head.appendChild(script);
  }
});

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 → Console → type window.affonso_referral
  4. Deploy and verify tracking in your Affonso dashboard

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.