NextAuth.js
تتبّع العملاء المحتملين
Configure NextAuth to track lead conversion events when a new user signs up.
- Use NextAuth's
signInevent to detect when there's a new sign up. - If the user is a new sign up, check if the
daboos_idcookie is present. - If the
daboos_idcookie is present, send a lead event to Daboos usingdaboos.track.lead. - Delete the
daboos_idcookie.
Under the hood, Daboos records the user as a customer and associates them with the click event that they came from. The user's unique ID is now the source of truth for all future events – hence why we don't need the daboos_id cookie anymore.
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/[...nextauth]/options.ts
import { daboos } from "@/lib/daboos";
import type { NextAuthOptions } from "next-auth";
import { cookies } from "next/headers";
export const authOptions: NextAuthOptions = {
...otherAuthOptions, // your other NextAuth options
events: {
async signIn({ user, isNewUser }) {
// if it's a new sign up
if (isNewUser) {
// check if the daboos_id cookie is present
const clickId = cookies().get("daboos_id")?.value;
if (clickId) {
// send lead event to Daboos
await daboos.track.lead({
clickId,
eventName: "Sign Up",
customerExternalId: user.id,
customerName: user.name,
customerEmail: user.email,
customerAvatar: user.image,
});
// delete the click id cookie
cookies().set("daboos_id", "", { expires: new Date(0) });
}
}
},
},
};
For the full SDK reference, see the developer docs.