The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add CTA buttons to widget
Tim Wilson0e44cecf1a13
diff --git a/apps/web/app/app.dub.co/embed/utils.ts b/apps/web/app/app.dub.co/embed/utils.tsindex 60551613bd..677abbc48c 100644--- a/apps/web/app/app.dub.co/embed/utils.ts+++ b/apps/web/app/app.dub.co/embed/utils.ts@@ -2,27 +2,28 @@ import { embedToken } from "@/lib/embed/embed-token";import { prisma } from "@/lib/prisma";import { notFound } from "next/navigation";-export const getLinkAndProgram = async (token: string) => {+export const getEmbedData = async (token: string) => {const linkId = await embedToken.get(token);if (!linkId) {notFound();}- const linkAndProgram = await prisma.link.findUnique({+ const linkWithIncludes = await prisma.link.findUnique({where: {id: linkId,},include: {program: true,+ programEnrollment: true,},});- if (!linkAndProgram) {+ if (!linkWithIncludes) {notFound();}- const { program, ...link } = linkAndProgram;+ const { program, programEnrollment, ...link } = linkWithIncludes;if (!program) {notFound();@@ -30,6 +31,7 @@ export const getLinkAndProgram = async (token: string) => {return {program,+ programEnrollment,link,earnings:(program.commissionType === "percentage" ? link.saleAmount : link.sales) *diff --git a/apps/web/app/app.dub.co/embed/widget/page-client.tsx b/apps/web/app/app.dub.co/embed/widget/page-client.tsxindex 25166dcd8d..e39b2c64de 100644--- a/apps/web/app/app.dub.co/embed/widget/page-client.tsx+++ b/apps/web/app/app.dub.co/embed/widget/page-client.tsx@@ -4,6 +4,7 @@ import { PartnerSaleResponse } from "@/lib/types";import {AnimatedSizeContainer,Button,+ buttonVariants,LoadingSpinner,ToggleGroup,useCopyToClipboard,@@ -40,10 +41,12 @@ export function EmbedWidgetPageClient({program,link,earnings,+ isEnrolled,}: {program: Program;link: Link;earnings: number;+ isEnrolled: boolean;}) {const [copied, copyToClipboard] = useCopyToClipboard();const [selectedTab, setSelectedTab] = useState<Tab>("invite");@@ -136,7 +139,7 @@ export function EmbedWidgetPageClient({indicatorClassName="rounded-lg bg-white border border-neutral-100 shadow-sm"/>- <div className="mt-6">+ <div className="mt-5">{selectedTab === "invite" && (<><div className="flex flex-col gap-2">@@ -207,9 +210,12 @@ export function EmbedWidgetPageClient({Activity</h2><motion.div- initial={{ height: 0, opacity: 0 }}+ initial={{ height: 150, opacity: 0 }}animate={{ height: "auto", opacity: 1 }}- transition={{ duration: heroAnimationDuration }}+ transition={{+ duration: heroAnimationDuration + 0.05,+ ease: "easeInOut",+ }}className="overflow-clip"><div className="mt-3 grid grid-cols-3 gap-2">@@ -232,40 +238,88 @@ export function EmbedWidgetPageClient({))}</div><div className="mt-4">+ <h2 className="text-sm font-semibold text-neutral-900">+ Recent sales+ </h2>{sales ? (sales.length ? (- <div className="mt-4 grid grid-cols-1 divide-y divide-neutral-200 rounded-md border border-neutral-200">- {sales.slice(0, 3).map((sale) => (- <div- key={sale.id}- className="flex items-center justify-between gap-4 px-3 py-2.5"- >- <div className="flex min-w-0 flex-col">- <span className="truncate text-sm font-medium text-neutral-600">- {sale.customer.email}- </span>- </div>- <div className="flex flex-col">- <span className="text-sm font-medium text-neutral-600">- {currencyFormatter(sale.earnings / 100, {- minimumFractionDigits: 2,- maximumFractionDigits: 2,- })}- </span>- </div>- </div>- ))}+ <div className="mt-2.5 rounded-md border border-neutral-200">+ <div+ className={cn(+ "grid grid-cols-1",+ !isEnrolled &&+ "[mask-image:linear-gradient(black,transparent)]",+ )}+ >+ {sales+ .slice(0, isEnrolled ? 3 : 1)+ .map((sale, idx) => (+ <div+ key={sale.id}+ className={cn(+ "flex items-center justify-between gap-4 border-neutral-200 px-3 py-2.5",+ idx > 0 && "border-t",+ )}+ >+ <div className="flex min-w-0 flex-col">+ <span className="truncate text-sm font-medium text-neutral-600">+ {sale.customer.email}+ </span>+ </div>+ <div className="flex flex-col">+ <span className="text-sm font-medium text-neutral-600">+ {currencyFormatter(sale.earnings / 100, {+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ })}+ </span>+ </div>+ </div>+ ))}+ </div>+ {!isEnrolled && (+ <p className="px-8 py-4 text-center text-xs text-neutral-500">+ To withdraw your earnings or view all of your sales,+ create a free Dub partner account below.+ </p>+ )}</div>) : (<EmptyState />)) : isLoading ? (- <div className="mt-8 flex items-center justify-center">+ <div className="mt-6 flex items-center justify-center"><LoadingSpinner className="size-4" /></div>) : (<EmptyState />)}+ {!isLoading &&+ sales &&+ sales.length > 0 &&+ (isEnrolled ? (+ <a+ href="https://partners.dub.co/settings/payouts"+ target="_blank"+ className={cn(+ buttonVariants({ variant: "primary" }),+ "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",+ )}+ >+ Withdraw earnings+ </a>+ ) : (+ <a+ href="https://partners.dub.co/register"+ target="_blank"+ className={cn(+ buttonVariants({ variant: "primary" }),+ "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",+ )}+ >+ Create partner account+ </a>+ ))}</div></motion.div></>@@ -291,7 +345,7 @@ export function EmbedWidgetPageClient({const EmptyState = () => {return (- <div className="flex h-40 w-full flex-col items-center justify-center gap-2 rounded-lg border border-neutral-200 bg-neutral-50">+ <div className="mt-2.5 flex h-40 w-full flex-col items-center justify-center gap-2 rounded-lg border border-neutral-200 bg-neutral-50"><Gift className="size-6 text-neutral-400" /><p className="max-w-60 text-pretty text-center text-xs text-neutral-400">No sales yet. When you refer a friend and they make a purchase, they'lldiff --git a/apps/web/app/app.dub.co/embed/widget/page.tsx b/apps/web/app/app.dub.co/embed/widget/page.tsxindex dae7b859d7..c5256f0b77 100644--- a/apps/web/app/app.dub.co/embed/widget/page.tsx+++ b/apps/web/app/app.dub.co/embed/widget/page.tsx@@ -1,4 +1,4 @@-import { getLinkAndProgram } from "../utils";+import { getEmbedData } from "../utils";import { EmbedWidgetPageClient } from "./page-client";export default async function EmbedWidgetPage({@@ -8,9 +8,15 @@ export default async function EmbedWidgetPage({}) {const { token } = searchParams;- const { link, program, earnings } = await getLinkAndProgram(token);+ const { link, program, programEnrollment, earnings } =+ await getEmbedData(token);return (- <EmbedWidgetPageClient program={program} link={link} earnings={earnings} />+ <EmbedWidgetPageClient+ program={program}+ link={link}+ earnings={earnings}+ isEnrolled={!!programEnrollment}+ />);}diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.tsindex 19803fd848..ee08ecdc38 100644--- a/packages/embeds/core/src/core.ts+++ b/packages/embeds/core/src/core.ts@@ -25,7 +25,7 @@ const POPUP_STYLES: Partial<CSSStyleDeclaration> = {width: "100%",height: "100%",maxWidth: "400px",- maxHeight: "500px",+ maxHeight: "510px",backgroundColor: "white",borderRadius: "12px",boxShadow: "0px 8px 30px rgba(0, 0, 0, 0.12), 0px 2px 4px rgba(0, 0, 0, 0.1)",