Stripe Affiliate Tracking: Complete Integration Guide | AffiliateBase

Track affiliate conversions automatically with Stripe webhooks

Complete guide to tracking affiliate conversions with Stripe subscriptions, one-time payments, and recurring revenue

Stripe is the leading payment processor for SaaS and membership businesses, handling billions in transactions annually. If you're using Stripe for payments and want to track affiliate conversions accurately, you need a solution that integrates deeply with Stripe's webhook system.

This comprehensive guide will walk you through everything you need to know about setting up affiliate tracking with Stripe, from webhook configuration to tracking subscription lifecycle events like renewals, upgrades, and downgrades.

Whether you're processing one-time payments, subscriptions, or both, AffiliateBase's Stripe integration ensures every conversion is tracked accurately, even when ad blockers are present.

Follow these steps to set up Stripe affiliate tracking:

1

Configure Stripe Webhooks

Set up webhooks in your Stripe Dashboard to send payment events to AffiliateBase. Navigate to Developers > Webhooks and create a new endpoint.
text
https://api.affiliatebase.com/webhooks/stripe
2

Select Webhook Events

Subscribe to the following Stripe events for complete affiliate tracking: payment_intent.succeeded, customer.subscription.created, customer.subscription.updated, invoice.payment_succeeded, and checkout.session.completed.
3

Add Webhook Secret to AffiliateBase

Copy your webhook signing secret from Stripe and add it to your AffiliateBase dashboard under Settings > Integrations > Stripe.
4

Test Webhook Integration

Use Stripe's webhook testing tool or create a test payment to verify that events are being received and processed correctly.
bash
// Example: Test webhook locally using Stripe CLI
stripe listen --forward-to localhost:3000/api/webhooks/stripe
stripe trigger payment_intent.succeeded
5

Track Subscription Lifecycle Events

AffiliateBase automatically tracks subscription renewals, upgrades, downgrades, and cancellations through Stripe webhooks, ensuring accurate commission attribution.

Complete Stripe Webhook Handler Example

Here's a complete example of handling Stripe webhooks for affiliate tracking:

// Example: Next.js API route for Stripe webhooks
import { headers } from 'next/headers';
import Stripe from 'stripe';
import { AffiliateBase } from '@affiliatebase/sdk';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const affiliateBase = new AffiliateBase({
  apiKey: process.env.AFFILIATEBASE_API_KEY!,
});

export async function POST(request: Request) {
  const body = await request.text();
  const signature = headers().get('stripe-signature')!;
  
  let event: Stripe.Event;
  
  try {
    event = stripe.webhooks.constructEvent(
      body,
      signature,
      process.env.STRIPE_WEBHOOK_SECRET!
    );
  } catch (err) {
    return new Response(`Webhook Error: ${err.message}`, { status: 400 });
  }
  
  // Handle different event types
  switch (event.type) {
    case 'checkout.session.completed':
      const session = event.data.object as Stripe.Checkout.Session;
      await affiliateBase.trackConversion({
        affiliateId: session.metadata?.affiliateId,
        type: 'subscription',
        amount: session.amount_total! / 100,
        currency: session.currency!,
        customerId: session.customer as string,
        subscriptionId: session.subscription as string,
      });
      break;
      
    case 'customer.subscription.created':
    case 'invoice.payment_succeeded':
      const subscription = event.data.object as Stripe.Subscription;
      await affiliateBase.trackConversion({
        affiliateId: subscription.metadata?.affiliateId,
        type: 'subscription_renewal',
        amount: subscription.items.data[0].price.unit_amount! / 100,
        currency: subscription.currency,
        customerId: subscription.customer as string,
        subscriptionId: subscription.id,
      });
      break;
      
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object as Stripe.PaymentIntent;
      await affiliateBase.trackConversion({
        affiliateId: paymentIntent.metadata?.affiliateId,
        type: 'one_time_payment',
        amount: paymentIntent.amount / 100,
        currency: paymentIntent.currency,
        customerId: paymentIntent.customer as string,
      });
      break;
  }
  
  return new Response(JSON.stringify({ received: true }), { status: 200 });
}

Why Use AffiliateBase for Stripe Tracking?

AffiliateBase provides the most reliable and comprehensive Stripe affiliate tracking solution for SaaS and membership businesses.

Server-Side Tracking

Track conversions via Stripe webhooks on the server, ensuring accuracy even when ad blockers are present. No reliance on cookies or client-side tracking.

Subscription Lifecycle Tracking

Automatically track subscription renewals, upgrades, downgrades, and cancellations. Get accurate attribution for recurring revenue, not just initial sign-ups.

Real-Time Processing

Process Stripe webhooks in real-time for instant conversion tracking and commission attribution. No delays or batch processing.

Automatic Commission Calculation

Automatically calculate commissions based on your configured rules, whether it's a percentage of revenue, fixed amount, or tiered structure.

Handles All Payment Types

Track one-time payments, subscriptions, setup fees, and usage-based billing. Supports all Stripe payment methods and business models.

Webhook Security

Built-in webhook signature verification ensures only legitimate Stripe events are processed, protecting your affiliate program from fraud.

Frequently Asked Questions

How does Stripe affiliate tracking work?

AffiliateBase uses Stripe webhooks to receive payment events in real-time. When a customer completes a payment (one-time or subscription), Stripe sends a webhook to AffiliateBase, which then attributes the conversion to the correct affiliate and calculates commissions automatically.

Do I need to modify my Stripe checkout?

No, you don't need to modify your Stripe checkout flow. AffiliateBase tracks conversions through webhooks, so it works with Stripe Checkout, Payment Links, and custom payment forms. You can optionally pass affiliate IDs through Stripe metadata for more control.

How are subscription renewals tracked?

AffiliateBase automatically tracks subscription renewals through Stripe's invoice.payment_succeeded webhook. Each renewal is attributed to the original affiliate, ensuring they receive commissions for the lifetime of the subscription.

What happens when a customer upgrades or downgrades?

AffiliateBase tracks subscription changes through the customer.subscription.updated webhook. Commissions are calculated based on the new subscription amount, and the original affiliate maintains attribution.

Is server-side tracking more reliable than client-side?

Yes! Server-side tracking via webhooks is more reliable because it can't be blocked by ad blockers, doesn't rely on cookies, and processes events directly from Stripe. This ensures 100% accuracy for conversion tracking.

Can I track both one-time payments and subscriptions?

Absolutely! AffiliateBase handles both one-time payments (via payment_intent.succeeded) and subscriptions (via subscription and invoice webhooks) seamlessly. You can configure different commission structures for each payment type.

What if a webhook fails to process?

AffiliateBase includes automatic retry logic for failed webhooks. If a webhook fails to process, it will be retried with exponential backoff. You can also view webhook delivery status in your AffiliateBase dashboard.

Ready to Set Up Stripe Affiliate Tracking?

Get started with AffiliateBase today and start tracking Stripe conversions accurately with server-side webhooks.