Refficks

Next.js affiliate tracking with Refficks

Stripe Checkout Sessions your Next.js app creates, credited to the partner whose link brought the buyer.

Nobody has walked these steps against a real Next.js setup yet. They are built from the provider's documentation, listed at the bottom of this page.

What it gives you

  • A payment through a Checkout Session your app opens is credited to the partner whose link brought the buyer, straight from the payment in your Stripe account.
  • A subscription keeps its partner for every renewal, a refund takes the commission back by itself, and partners' codes synced to Stripe work at the checkout as they are.

What it does not

  • A visitor who has not accepted cookies, or whose browser sends Global Privacy Control, has no visitor id to pass on. Their sale can still be credited through the partner's discount code.
  • Only Checkout Sessions on a Stripe account connected to Refficks are seen. Payments taken some other way need their own guide.

Steps

These are the steps as they read inside Refficks. Where one says “below”, it means this guide's page in Refficks, where your own script, addresses and checks are.

  1. 1. Put the Refficks script on every page

    Paste the snippet into the head of every page, in your app's main layout. It records the partner's click when somebody arrives and keeps their visitor id in a first-party cookie, rk_vid.

    Your copy of the Refficks script, with your own key in it, is on the Integrations page in Refficks.

  2. 2. Pass the visitor to Stripe

    In the route handler or server action that creates the Checkout Session, read the rk_vid cookie and give it to Stripe as refficks_visitor, in the session's metadata and, for a subscription, in subscription_data's metadata. Leave the rest of your checkout as it is.

    If the code that creates the session runs on another domain than your site, the cookie does not reach it. Send window.refficks.visitorId() from the page with the request instead, and use that.

    import { cookies } from "next/headers";
    
    // Where your route handler or server action creates the session:
    const visitor = (await cookies()).get("rk_vid")?.value;
    const refficks = visitor ? { refficks_visitor: visitor } : {};
    
    const session = await stripe.checkout.sessions.create({
      // ...your line items, mode and return URLs, as now...
      metadata: refficks,
      // Only for a subscription:
      subscription_data: { metadata: refficks },
    });
  3. 3. Make a test purchase

    Open your site through any partner's link, copied from their page under Partners, and buy something with Stripe in test mode. The checks on this guide in Refficks turn green as each part is seen. A test payment is never counted as a sale.

Sources

Have an account? Open this guide in Refficks for your own script and the checks that show when it is working. New to Refficks? Create an account.

More in Your checkout code