// snippet import removed // snippet import removed // snippet import removed // snippet import removed
In this guide, we will be focusing on tracking new user sign-ups for a SaaS application that uses Auth0 for user authentication.
Configure Auth0
Next, configure Auth0 to track lead conversion events.
Here’s how it works in a nutshell:
- In the sign in
afterCallbackfunction, check if the user is a new sign up. - If the user is a new sign up, check if the
dub_idcookie is present. - If the
dub_idcookie is present, send a lead event to Dub usingdub.track.lead - Delete the
dub_idcookie.
import { handleAuth, handleCallback, type Session } from "@auth0/nextjs-auth0";
import { cookies } from "next/headers";
import { dub } from "@/lib/dub";
const afterCallback = async (req: Request, session: Session) => {
const userExists = await getUser(session.user.email);
if (!userExists) {
createUser(session.user);
// check if dub_id cookie is present
const clickId = cookies().get("dub_id")?.value;
if (clickId) {
// send lead event to Dub
await dub.track.lead({
clickId,
eventName: "Sign Up",
customerExternalId: session.user.id,
customerName: session.user.name,
customerEmail: session.user.email,
customerAvatar: session.user.image,
});
// delete the dub_id cookie
cookies().set("dub_id", "", {
expires: new Date(0),
});
}
return session;
}
};
export default handleAuth({
callback: handleCallback({ afterCallback }),
});