Nuxt is a powerful Vue.js framework that makes it easy to build server-rendered and static web applications. If you're looking to monetize your Nuxt app through an affiliate program, you've come to the right place.
This comprehensive guide will walk you through everything you need to know about setting up an affiliate program with Nuxt, from initial setup to tracking conversions using Nuxt's server routes and composables.
Whether you're building a SaaS product, membership platform, or subscription service with Stripe, an affiliate program can help you grow your user base and increase revenue.
Follow these steps to get your affiliate program up and running in Nuxt:
Add the Tracking Script
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{
innerHTML: '(function(w,r){w._abq=w._abq||[];w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}})(window,"affiliatebase");',
},
{
src: 'https://cdn.jsdelivr.net/npm/affiliatebase-tracking@1/src/index.js',
async: true,
'data-org-id': 'YOUR_ORG_ID',
},
],
},
},
})
Or Install via npm
npm install affiliatebase-tracking
// In a Nuxt plugin (plugins/affiliatebase.client.ts)
import 'affiliatebase-tracking';
export default defineNuxtPlugin(() => {
// Plugin runs client-side only
});
Create a Composable
// composables/useAffiliateTracking.ts
export const useAffiliateTracking = () => {
const referralId = ref<string>('');
const isReady = ref(false);
onMounted(() => {
if (typeof window !== 'undefined' && window.affiliatebase) {
window.affiliatebase('ready', () => {
referralId.value = window.affiliatebase_referral || '';
isReady.value = true;
});
}
});
const trackConversion = (email: string) => {
window.affiliatebase?.('convert', { email });
};
return { referralId, isReady, trackConversion };
};
Create Server API Route
// server/api/checkout.post.ts
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { referralId, priceId } = body;
const session = await stripe.checkout.sessions.create({
success_url: `${process.env.NUXT_PUBLIC_URL}/success`,
cancel_url: `${process.env.NUXT_PUBLIC_URL}/cancel`,
customer_creation: 'always',
...(referralId && { client_reference_id: referralId }),
line_items: [{ price: priceId, quantity: 1 }],
mode: 'subscription',
});
return { url: session.url };
});
Use in Components
<!-- pages/pricing.vue -->
<script setup>
const { referralId } = useAffiliateTracking();
const handleCheckout = async () => {
const { url } = await $fetch('/api/checkout', {
method: 'POST',
body: {
referralId: referralId.value,
priceId: 'price_xxx',
},
});
navigateTo(url, { external: true });
};
</script>
<template>
<button @click="handleCheckout">Subscribe</button>
</template>
Why Use AffiliateBase with Nuxt?
AffiliateBase is the perfect solution for Nuxt developers who want to launch an affiliate program quickly and efficiently.
Nuxt 3 Ready
Works seamlessly with Nuxt 3 server routes, composables, and plugins.
Vue Composables
Use Nuxt composables for clean, reusable affiliate tracking logic.
SSR Compatible
Fully compatible with Nuxt's server-side rendering and static site generation.
TypeScript Support
Full TypeScript support for type-safe affiliate tracking.
Frequently Asked Questions
Does AffiliateBase work with Nuxt 3?
Can I use AffiliateBase with Nuxt static site generation?
How do I access the referral ID in Nuxt?
What tracking parameters does AffiliateBase support?
Related Platform Guides
Create an Affiliate Program with Next.js
Complete guide to setting up an affiliate program in Next.js. Step-by-step integration with code examples and best practices for Next.js developers.
Create an Affiliate Program with WordPress
Complete guide to setting up an affiliate program in WordPress. Step-by-step integration with WordPress themes, plugins, and WooCommerce for any WordPress site.
Create an Affiliate Program with Webflow
Complete guide to setting up an affiliate program in Webflow. Step-by-step integration with Webflow CMS, custom code, and forms for no-code developers.
Create an Affiliate Program with React
Complete guide to setting up an affiliate program in React. Step-by-step integration with React hooks, context, and components for React developers.
Create an Affiliate Program with Vue
Complete guide to setting up an affiliate program in Vue. Step-by-step integration with Vue 3, composables, and plugins for Vue developers.
Ready to Launch Your Nuxt Affiliate Program?
Get started with AffiliateBase today and start growing your business with affiliate marketing.