@refport/better-auth
v0.1.3
Published
Better Auth plugin for Refport referral tracking
Maintainers
Readme
@refport/better-auth
Better Auth plugin for Refport referral tracking. Automatically tracks sign-up conversions as leads when users register through a referral link.
Installation
npm install @refport/better-auth refportServer Setup
Add the plugin to your Better Auth server configuration:
import { betterAuth } from "better-auth";
import { refportPlugin } from "@refport/better-auth";
import { Refport } from "refport";
const refport = new Refport({ apiKey: process.env.REFPORT_API_KEY! });
export const auth = betterAuth({
plugins: [
refportPlugin({
refport,
}),
],
});Client Setup
Add the client plugin for type inference:
import { createAuthClient } from "better-auth/client";
import { refportPluginClient } from "@refport/better-auth/client";
export const authClient = createAuthClient({
plugins: [refportPluginClient()],
});Options
| Option | Type | Default | Description |
| ----------------- | ------------------------------ | ------------ | ------------------------------------------- |
| refport | Refport | required | Refport SDK instance |
| eventName | string | "Sign Up" | Event name for the lead conversion |
| cookieName | string | "refp_id" | Name of the cookie that stores the click ID |
| customLeadTrack | (user, ctx) => Promise<void> | — | Override the default tracking logic |
How It Works
- A visitor clicks a referral link and lands on your site
- The
refport-jsbrowser SDK captures therefp_idURL parameter into a cookie - The visitor signs up using Better Auth
- This plugin's
user.create.afterdatabase hook fires:- Reads the
refp_idcookie from the request - Calls
refport.track.lead()with the user's details - Clears the cookie
- Reads the
- The referral is now attributed in your Refport dashboard
Errors during tracking are logged but never block the sign-up flow.
