First, you need to create a server API route that generates a public token, which will be used by the Dub Referrals Embed 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({ programId: "prog_xxx", // program ID from your Dub dashboard (in the URL) 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 },});
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({ programId: "prog_xxx", // program ID from your Dub dashboard 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 }, }),});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.