Refficks

Auth.js (NextAuth) affiliate tracking with Refficks

New accounts in your app's Auth.js (NextAuth) sign-up, tied to the partner whose link brought them, so their later payment is credited to that partner.

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

What it gives you

  • Somebody who arrives through a partner's link and then creates an account in your app is tied to that partner. When they later pay, through any payment connection Refficks receives, the sale is credited to the partner who sent them.
  • A referral programme that rewards "they create an account" counts it.

What it does not

  • Auth.js knows a user is new only for accounts it creates in its database through an adapter. That leaves out the Credentials provider: name those people where your own sign-up code creates the account.
  • Only new accounts are named, never every sign-in: somebody who signed up before following a partner's link would otherwise read as an account that partner brought.
  • A partner is paid when that person pays, and the payment has to reach Refficks from a connection that names the same email.
  • A visitor who has not accepted cookies, or whose browser sends Global Privacy Control, is not named.

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 of your app, in its main layout. It records the partner's click when somebody arrives.

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

  2. 2. Send new users to a welcome page

    Add the line below to the pages setting in your Auth.js configuration. Auth.js sends somebody there on their first sign-in, and nowhere new after that.

    pages: { newUser: "/welcome" },
  3. 3. Name them on the welcome page

    Make app/welcome/page.jsx like this. It needs <SessionProvider> around your app, as useSession always does.

    "use client";
    import { useEffect } from "react";
    import { useSession } from "next-auth/react";
    
    export default function Welcome() {
      const { data: session, status } = useSession();
    
      useEffect(() => {
        if (status !== "authenticated" || !session?.user?.email) return;
        (function say(tries) {
          if (!window.refficks) return tries < 40 && setTimeout(() => say(tries + 1), 250);
          window.refficks.identify({ email: session.user.email });
        })(0);
      }, [status, session]);
    
      // Then send them on, as your sign-up does now.
      return <p>Welcome! Setting up your account…</p>;
    }
  4. 4. Try it

    Open your app through any partner's link, copied from their page under Partners, and create an account. The checks on this guide in Refficks say when the new account was named, and when a sale is credited once that person pays.

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 sign-in