Better Auth affiliate tracking with Refficks
New accounts in your app's Better Auth sign-up, tied to the partner whose link brought them, so their later payment is credited to that partner.
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
- 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
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.
2. Name them when they sign up with an email
Where your sign-up form calls authClient.signUp.email(), add the onSuccess below.
// Where your sign-up form calls Better Auth: await authClient.signUp.email( { email, password, name }, { onSuccess: () => { (function say(tries) { if (!window.refficks) return tries < 40 && setTimeout(() => say(tries + 1), 250); window.refficks.identify({ email }); })(0); }, }, );3. Send new accounts from sign-in buttons to a welcome page
If you have Google, GitHub or other sign-in buttons, give each one a newUserCallbackURL. Better Auth uses it only when the sign-in made a new account.
await authClient.signIn.social({ provider: "google", callbackURL: "/", newUserCallbackURL: "/welcome", });4. Name them on the welcome page
Make app/welcome/page.jsx (or your welcome route) like this, importing authClient from wherever you created it.
"use client"; import { useEffect } from "react"; import { authClient } from "@/lib/auth-client"; export default function Welcome() { const { data: session, isPending } = authClient.useSession(); useEffect(() => { if (isPending || !session) return; (function say(tries) { if (!window.refficks) return tries < 40 && setTimeout(() => say(tries + 1), 250); window.refficks.identify({ email: session.user.email, external_id: session.user.id }); })(0); }, [isPending, session]); // Then send them on, as your sign-up does now. return <p>Welcome! Setting up your account…</p>; }5. 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.