Supabase
تتبّع العملاء المحتملين
Configure Supabase to track lead conversion events in the auth callback function.
Here's how it works in a nutshell:
- In the
/api/auth/callbackroute, check if:- the
daboos_idcookie is present. - the user is a new sign up (created in the last 10 minutes).
- the
- If the
daboos_idcookie is present and the user is a new sign up, send a lead event to Daboos usingdaboos.track.lead. - Delete the
daboos_idcookie.
Install the SDK, add your API key and API URL to your environment variables, and create a Daboos client.
npm install daboos
DABOOS_API_KEY=dbs_xxxxxx
DABOOS_API_URL=https://app.meshify3d.com/api
Create a Daboos client. It reads DABOOS_API_KEY and DABOOS_API_URL from your environment.
// lib/daboos.ts
import { Daboos } from "daboos";
export const daboos = new Daboos();
// app/api/auth/callback/route.ts
import { daboos } from "@/lib/daboos";
import { createClient } from "@/lib/supabase/server";
import { waitUntil } from "@vercel/functions";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
const code = searchParams.get("code");
// if "next" is in param, use it as the redirect URL
const next = searchParams.get("next") ?? "/";
if (code) {
const supabase = createClient(cookies());
const { data, error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) {
const { user } = data;
const clickId = cookies().get("daboos_id")?.value;
// if the user is created in the last 10 minutes, consider them new
const isNewUser =
new Date(user.created_at) > new Date(Date.now() - 10 * 60 * 1000);
// if the user is new and has a click id cookie, track the lead
if (clickId && isNewUser) {
waitUntil(
daboos.track.lead({
clickId,
eventName: "Sign Up",
customerExternalId: user.id,
customerName: user.user_metadata.name,
customerEmail: user.email,
customerAvatar: user.user_metadata.avatar_url,
}),
);
// delete the click id cookie
cookies().delete("daboos_id");
}
return NextResponse.redirect(`${origin}${next}`);
}
}
// return the user to an error page with instructions
return NextResponse.redirect(`${origin}/auth/auth-code-error`);
}
For the full SDK reference, see the developer docs.