The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add conversion scores
Tim Wilson7f573ff0bfc9
diff --git a/apps/web/app/(ee)/api/network/partners/route.ts b/apps/web/app/(ee)/api/network/partners/route.tsindex 237c1aa9e2..5831254656 100644--- a/apps/web/app/(ee)/api/network/partners/route.ts+++ b/apps/web/app/(ee)/api/network/partners/route.ts@@ -1,3 +1,4 @@+import { getConversionScore } from "@/lib/actions/partners/get-conversion-score";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";import { withWorkspace } from "@/lib/auth";import {@@ -21,7 +22,8 @@ export const GET = withWorkspace(industryInterests.industryInterests,preferredEarningStructures.preferredEarningStructures,salesChannels.salesChannels,- metrics.lastConversionAt as lastConversionAt+ metrics.lastConversionAt as lastConversionAt,+ metrics.conversionRate as conversionRateFROMPartner p-- Any associated program enrollment@@ -30,8 +32,11 @@ export const GET = withWorkspace(LEFT JOIN (SELECTpartnerId,- MAX(lastConversionAt) as lastConversionAt+ MAX(lastConversionAt) as lastConversionAt,+ SUM(conversions) / COALESCE(SUM(clicks), 0) as conversionRateFROM Link+ WHERE programId IS NOT NULL+ AND partnerId IS NOT NULLGROUP BY partnerId) metrics ON metrics.partnerId = p.id-- Profile field lists@@ -51,8 +56,7 @@ export const GET = withWorkspace(GROUP BY partnerId) salesChannels ON salesChannels.partnerId = p.idWHERE- p.discoverableAt IS NOT NULL- AND pe.id IS NULL+ p.discoverableAt IS NOT NULL -- AND pe.id IS NULLLIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`) satisfies Array<any>;return NextResponse.json(@@ -63,6 +67,10 @@ export const GET = withWorkspace(preferredEarningStructures:partner.preferredEarningStructures?.split(",") || undefined,salesChannels: partner.salesChannels?.split(",") || undefined,+ conversionScore:+ partner.conversionRate === null+ ? null+ : getConversionScore(partner.conversionRate),})),),);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsxindex 565f5e3681..61adc3dd62 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx@@ -7,10 +7,15 @@ import {} from "@/lib/partners/partner-profile";import useWorkspace from "@/lib/swr/use-workspace";import { DiscoverablePartnerProps } from "@/lib/types";-import { X } from "@/ui/shared/icons";+import {+ PARTNER_CONVERSION_SCORES,+ PARTNER_CONVERSION_SCORE_RATES,+} from "@/lib/zod/schemas/partner-discovery";+import { ConversionScoreIcon } from "@/ui/partners/conversion-score-icon";import {BadgeCheck2Fill,ChartActivity2,+ DynamicTooltipWrapper,Tooltip,UserPlus,useResizeObserver,@@ -20,6 +25,7 @@ import type { Icon } from "@dub/ui/icons";import {COUNTRIES,OG_AVATAR_URL,+ capitalize,cn,fetcher,formatDate,@@ -138,8 +144,17 @@ function PartnerCard({ partner }: { partner?: DiscoverablePartnerProps }) {},{id: "conversion",- icon: <X className="size-3.5 shrink-0" />,- text: partner ? `XXXX conversion` : undefined,+ icon: (+ <ConversionScoreIcon+ score={partner?.conversionScore || null}+ className="size-3.5 shrink-0"+ />+ ),+ text: partner+ ? partner.conversionScore+ ? `${capitalize(partner.conversionScore)} conversion`+ : "Unknown conversion"+ : undefined,},],[partner],@@ -196,23 +211,79 @@ function PartnerCard({ partner }: { partner?: DiscoverablePartnerProps }) {)}{/* Basic details */}- <div className="flex flex-col gap-1">+ <div className="flex flex-col items-start gap-1">{basicFields.filter(({ text }) => text !== null).map(({ id, icon, text }) => (- <div+ <DynamicTooltipWrapperkey={id}- className="text-content-subtle flex items-center gap-1"+ tooltipProps={+ id === "conversion"+ ? {+ content: (+ <div className="max-w-60 p-2.5 text-xs">+ <div className="flex flex-col gap-2.5">+ {PARTNER_CONVERSION_SCORES.map((score, idx) => (+ <div+ key={score}+ className="flex items-center gap-1.5"+ >+ <ConversionScoreIcon+ score={score}+ className="size-3.5 shrink-0"+ />+ <span className="text-content-default font-semibold">+ {capitalize(score)}{" "}+ <span className="text-content-subtle font-medium">+ (+ {idx <+ PARTNER_CONVERSION_SCORES.length - 1 ? (+ <>+ {PARTNER_CONVERSION_SCORE_RATES[+ score+ ] * 100}+ -+ {PARTNER_CONVERSION_SCORE_RATES[+ PARTNER_CONVERSION_SCORES[idx + 1]+ ] * 100}+ </>+ ) : (+ <>+ >+ {PARTNER_CONVERSION_SCORE_RATES[+ score+ ] * 100}+ </>+ )}+ %)+ </span>+ </span>+ </div>+ ))}+ </div>+ <p className="text-content-subtle mt-4 font-medium">+ This score is an average for all Dub programs the+ partner is enrolled in.+ </p>+ </div>+ ),+ side: "right",+ align: "end",+ }+ : undefined+ }>- {text !== undefined ? (- <>- {icon}- <span className="text-xs font-medium">{text}</span>- </>- ) : (- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />- )}- </div>+ <div className="text-content-subtle flex cursor-default items-center gap-1">+ {text !== undefined ? (+ <>+ {icon}+ <span className="text-xs font-medium">{text}</span>+ </>+ ) : (+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />+ )}+ </div>+ </DynamicTooltipWrapper>))}</div>diff --git a/apps/web/lib/actions/partners/get-conversion-score.ts b/apps/web/lib/actions/partners/get-conversion-score.tsnew file mode 100644index 0000000000..9231583b55--- /dev/null+++ b/apps/web/lib/actions/partners/get-conversion-score.ts@@ -0,0 +1,16 @@+import { PartnerConversionScore } from "@/lib/types";+import { PARTNER_CONVERSION_SCORE_RATES } from "@/lib/zod/schemas/partner-discovery";++export function getConversionScore(+ conversionRate: number,+): PartnerConversionScore {+ return conversionRate > PARTNER_CONVERSION_SCORE_RATES.excellent+ ? "excellent"+ : conversionRate > PARTNER_CONVERSION_SCORE_RATES.high+ ? "high"+ : conversionRate > PARTNER_CONVERSION_SCORE_RATES.good+ ? "good"+ : conversionRate > PARTNER_CONVERSION_SCORE_RATES.average+ ? "average"+ : "low";+}diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 5e2bfc5bec..0ef31adcc9 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -65,7 +65,10 @@ import {} from "./zod/schemas/links";import { MessageSchema } from "./zod/schemas/messages";import { createOAuthAppSchema, oAuthAppSchema } from "./zod/schemas/oauth";-import { DiscoverablePartnerSchema } from "./zod/schemas/partner-discovery";+import {+ DiscoverablePartnerSchema,+ PartnerConversionScoreSchema,+} from "./zod/schemas/partner-discovery";import {createPartnerSchema,EnrolledPartnerSchema,@@ -442,6 +445,10 @@ export type DiscoverablePartnerProps = z.infer<typeof DiscoverablePartnerSchema>;+export type PartnerConversionScore = z.infer<+ typeof PartnerConversionScoreSchema+>;+export type DiscountProps = z.infer<typeof DiscountSchema>;export type ProgramProps = z.infer<typeof ProgramSchema>;diff --git a/apps/web/lib/zod/schemas/partner-discovery.ts b/apps/web/lib/zod/schemas/partner-discovery.tsindex 234789d5bc..8feedf26fd 100644--- a/apps/web/lib/zod/schemas/partner-discovery.ts+++ b/apps/web/lib/zod/schemas/partner-discovery.ts@@ -2,6 +2,27 @@ import { z } from "zod";import { getPaginationQuerySchema } from "./misc";import { PartnerSchema } from "./partners";+export const PARTNER_CONVERSION_SCORES = [+ "low",+ "average",+ "good",+ "high",+ "excellent",+] as const;++export const PARTNER_CONVERSION_SCORE_RATES: Record<+ (typeof PARTNER_CONVERSION_SCORES)[number],+ number+> = {+ low: 0,+ average: 0.005,+ good: 0.01,+ high: 0.03,+ excellent: 0.05,+};++export const PartnerConversionScoreSchema = z.enum(PARTNER_CONVERSION_SCORES);+export const DISCOVERABLE_PARTNERS_MAX_PAGE_SIZE = 50;export const getDiscoverablePartnersQuerySchema = z@@ -44,5 +65,6 @@ export const DiscoverablePartnerSchema = PartnerSchema.pick({}).merge(z.object({lastConversionAt: z.date().nullable(),+ conversionScore: PartnerConversionScoreSchema.nullable(),}),);diff --git a/apps/web/ui/partners/conversion-score-icon.tsx b/apps/web/ui/partners/conversion-score-icon.tsxnew file mode 100644index 0000000000..c702465129--- /dev/null+++ b/apps/web/ui/partners/conversion-score-icon.tsx@@ -0,0 +1,83 @@+import { PartnerConversionScore } from "@/lib/types";+import { PARTNER_CONVERSION_SCORES } from "@/lib/zod/schemas/partner-discovery";+import { cn } from "@dub/utils";+import { SVGProps } from "react";++export function ConversionScoreIcon({+ score,+ className,+ ...rest+}: { score: PartnerConversionScore | null } & SVGProps<SVGSVGElement>) {+ const scoreIndex = PARTNER_CONVERSION_SCORES.indexOf(score || "low");++ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ className={cn(+ score+ ? {+ low: "text-red-600",+ average: "text-orange-600",+ good: "text-green-600",+ high: "text-blue-600",+ excellent: "text-violet-600",+ }[score]+ : "text-neutral-500",+ className,+ )}+ {...rest}+ >+ <g fill="currentColor">+ <path+ d="M16.135,7.75c-.522-3-2.885-5.363-5.885-5.885"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ opacity={scoreIndex > 0 ? 1 : 0.5}+ />+ <path+ d="M10.25,16.135c3-.522,5.363-2.885,5.885-5.885"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ opacity={scoreIndex > 1 ? 1 : 0.5}+ />+ <path+ d="M1.865,10.25c.522,3,2.885,5.363,5.885,5.885"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ opacity={scoreIndex > 2 ? 1 : 0.5}+ />+ <path+ d="M7.75,1.865c-3,.522-5.363,2.885-5.885,5.885"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ opacity={scoreIndex > 3 ? 1 : 0.5}+ />+ <circle+ cx="9"+ cy="9"+ fill="none"+ r="2.25"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}