With Dub Partners, you can build an embedded referral dashboard that lives directly inside your application in just a few lines of code.This way, your users can automatically enroll in your partner program without needing to leave your app and sign up on a third-party platform.
In this guide, we’ll walk you through the steps to get started with Dub’s embedded referral dashboard feature.
Looking to set up non-monetary rewards for your user referral partners? Read
the guide on how to set that up.
First, you need to create a server API route that generates a public token, which will be used by the embedded referral dashboard to fetch real-time conversions and earnings data from the client-side.
If you’re using our server-side SDKs, you can generate an embed token using the dub.embedTokens.referrals method.
const { publicToken } = await dub.embedTokens.referrals({ tenantId: user.id, // the user's ID within your application partner: { name: user.name, // the user's name email: user.email, // the user's email image: user.image, // the user's image/avatar tenantId: user.id, // the user's ID within your application groupId: "grp_xxxxxx", // optional: the partner's group ID on Dub (https://d.to/groups) },});
If you’re not using our server-side SDKs, you can generate an embed token using our REST API instead (via the POST /tokens/embed/referrals endpoint).
JavaScript
const response = await fetch("https://api.dub.co/tokens/embed/referrals", { method: "POST", body: JSON.stringify({ tenantId: user.id, // the user's ID within your application partner: { name: user.name, // the user's name email: user.email, // the user's email image: user.image, // the user's image/avatar tenantId: user.id, // the user's ID within your application groupId: "grp_xxxxxx", // optional: the partner's group ID on Dub (https://d.to/groups) }, }),});const data = await response.json();const { publicToken } = data;
Refer to the full API reference to learn more about the properties you can pass to the POST /tokens/embed/referrals endpoint.
When you call this endpoint, it first attempts to find an existing enrollment
using the provided tenantId. If no enrollment is found, it resolves the
partner by email and creates a new enrollment automatically. This means you
don’t need to handle enrollment logic separately – the endpoint guarantees a
valid enrollment and returns a usable embed token every time.