Difficulty: Intermediate Developer Required: Yes
If your app uses Supabase Auth, track the referral right after Supabase creates the new user. The examples use Next.js (App Router) with @supabase/ssr, but the same steps work in any framework.
How it works:
- The main tracking script on your website records the visit from a referral link and stores a
_fprom_tidcookie on your root domain. - When a new user signs up with Supabase Auth, your server reads the
_fprom_tidcookie. - Your server sends the user’s email, Supabase user ID and the
_fprom_tidvalue to the track/signup endpoint.
Main tracking script
Add the main tracking script to the<head> of every page a referral link can land on: your marketing site and your app. Replace <your-account-id-here> with your account ID from Settings > Integrations.
Referral tracking
1
Add your API credentials
Get your API key and Account ID from Settings > Integrations (create a new API key if you don’t have one yet), and add them to your server environment variables.
.env
2
Add a helper that tracks the signup
lib/firstpromoter.ts
3
Call it when a new user signs up
Pick the tab that matches how users sign up. If you support more than one method, add the code to each.
- OAuth and magic link
- Email and password
- Client-side only
Social logins (Google, GitHub…), magic links and email confirmation links all finish in your auth callback route. This route runs on every login, so the code only tracks users created in the last 10 minutes.
app/auth/callback/route.ts
uid is the Supabase user ID. FirstPromoter matches sales to referrals by email or uid, so send the same values your billing provider will send when the customer pays.