Skip to main content

Next.js Affiliate Program Setup with Stripe Checkout

Know what must work before you launch

Connect client-side referral capture to a server-created Stripe Checkout Session

Best fit
Teams evaluating AffiliateBase for a Next.js affiliate workflow.
Checkout handoff
The checkout path must receive the generated AffiliateBase referral ID.
Proof required
Complete one referred checkout and confirm the attributed sale and commission.

Follow the attribution evidence

Illustrative scenario · fictional values

  1. Referred visit

    ?via=partner

    AffiliateBase captures the visit and generates a referral record.

  2. Checkout handoff

    referral ID

    The checkout must carry the generated identifier into Stripe.

  3. Paid event

    $99 paid

    A supported Stripe event confirms the attributed payment.

  4. Commission

    $19.80 due

    An eligible attributed sale creates the commission record.

  5. Payout prep

    Payout ready

    Review the commission and prepare the next step with your payout provider.

This guide is for teams building their own merchant affiliate program in a Next.js application. It covers the App Router and the same client/server boundary also applies to Pages Router projects.

AffiliateBase captures the generated referral ID in the browser. A Route Handler, Server Action, or API route cannot read that browser value unless the client submits it. The server then creates Stripe Checkout with that generated ID, not the public token in the affiliate link.

Next.js documents sitewide third-party scripts in the root layout. Pair that placement with the Stripe handoff instructions and the verification checklist.

Implement and test the browser-to-server handoff:

1

Map the Checkout Request

Identify the Client Component that starts checkout and the server boundary that creates the Stripe Checkout Session. Hosted checkout alone does not preserve affiliate state.
2

Load the Tracking Script

Use Next.js’s supported Script component in the root or sales-route layout, preserving the account ID and data attributes from your AffiliateBase snippet.
html
<script async src="https://app.affiliatebase.io/track.js" data-account-id="YOUR_ACCOUNT_ID"></script>
3

Submit the Generated Referral ID

Read the generated referral ID in the browser and include it in the checkout request. Validate it on the server, set Stripe client_reference_id, and mirror it to the documented AffiliateBase metadata fields.
4

Test a Fresh Browser Session

Open the exact generated test affiliate link, start checkout from the tracked page, and complete a test-mode payment through the same server route used in production.
5

Confirm Sale and Commission

Verify the checkout event contains the generated UUID and that AffiliateBase creates the expected sale and commission. Test recurring billing separately.

What the Next.js Integration Separates

Client Referral Capture

The browser owns the affiliate click and generated referral state.

Server Checkout Creation

Your protected Stripe secret and Checkout Session creation remain server-side.

End-to-End Proof

A completed test checks the handoff, webhook processing, sale, and commission together.

Next.js Affiliate Tracking Questions

Can a Server Component read window.AffiliateBase?
No. Browser globals are available only on the client. Send the generated referral ID to your server checkout action or route.
Should client_reference_id contain the ?via value?
No. The ?via value is the public affiliate-link token. Stripe should receive the generated AffiliateBase referral ID.
Does loading the script prove checkout attribution?
No. Verify a test click, the generated referral ID on the completed Checkout Session, and the resulting sale and commission.

Related Platform Guides

Verify Your Next.js Checkout Path

Test one referral through the same client and server path your customers use.