The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add conversion unlocked popup
Tim Wilsond43e9cd72a89
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 3cfd3bf183..ce3484d5ce 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -24,6 +24,7 @@"@dub/tailwind-config": "workspace:*","@dub/ui": "workspace:*","@dub/utils": "workspace:*",+ "@floating-ui/react": "^0.26.20","@hookform/resolvers": "^3.9.0","@next-auth/prisma-adapter": "^1.0.5","@next/third-parties": "^15.1.0",diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex 16a7bc76e5..fa7ac20c06 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -272,6 +272,6 @@ export function AppSidebarNav({<Usage /></>}- />+ />);}diff --git a/apps/web/ui/layout/sidebar/usage.tsx b/apps/web/ui/layout/sidebar/usage.tsxindex 07f475cbc3..e8bdff01a5 100644--- a/apps/web/ui/layout/sidebar/usage.tsx+++ b/apps/web/ui/layout/sidebar/usage.tsx@@ -1,8 +1,15 @@"use client";import useWorkspace from "@/lib/swr/use-workspace";+import { X } from "@/ui/shared/icons";import ManageSubscriptionButton from "@/ui/workspaces/manage-subscription-button";-import { AnimatedSizeContainer, buttonVariants, Icon } from "@dub/ui";+import {+ AnimatedSizeContainer,+ Button,+ buttonVariants,+ Icon,+ useMediaQuery,+} from "@dub/ui";import { CircleDollar, CursorRays, Hyperlink } from "@dub/ui/icons";import {cn,@@ -11,12 +18,21 @@ import {INFINITY_NUMBER,nFormatter,} from "@dub/utils";+import {+ arrow,+ autoUpdate,+ FloatingArrow,+ FloatingPortal,+ offset,+ shift,+ useFloating,+} from "@floating-ui/react";import NumberFlow from "@number-flow/react";import { AnimatePresence, motion } from "framer-motion";-import { ChevronRight } from "lucide-react";+import { ChevronRight, Play } from "lucide-react";import Link from "next/link";import { useParams } from "next/navigation";-import { CSSProperties, useMemo, useState } from "react";+import { CSSProperties, forwardRef, useMemo, useRef, useState } from "react";export function Usage() {const { slug } = useParams() as { slug?: string };@@ -25,6 +41,8 @@ export function Usage() {}function UsageInner() {+ const { isMobile } = useMediaQuery();+const {usage,usageLimit,@@ -74,111 +92,113 @@ function UsageInner() {const warning = warnings.some((w) => w);+ const [salesRef, setSalesRef] = useState<HTMLDivElement | null>(null);+ const showConversionOnboarding =+ salesUsage === 0 && salesLimit && salesLimit > 0;+return loading || usage !== undefined ? (- <AnimatedSizeContainer height>- <div className="border-t border-neutral-300/80 p-3">- <Link- className="group flex items-center gap-0.5 text-sm font-normal text-neutral-500 transition-colors hover:text-neutral-700"- href={`/${slug}/settings/billing`}- >- Usage- <ChevronRight className="size-3 text-neutral-400 transition-[color,transform] group-hover:translate-x-0.5 group-hover:text-neutral-500" />- </Link>+ <>+ <AnimatedSizeContainer height>+ <div className="border-t border-neutral-300/80 p-3">+ <Link+ className="group flex items-center gap-0.5 text-sm font-normal text-neutral-500 transition-colors hover:text-neutral-700"+ href={`/${slug}/settings/billing`}+ >+ Usage+ <ChevronRight className="size-3 text-neutral-400 transition-[color,transform] group-hover:translate-x-0.5 group-hover:text-neutral-500" />+ </Link>- <div className="mt-4 flex flex-col gap-4">- <UsageRow- icon={CursorRays}- label="Events"- usage={usage}- limit={usageLimit}- showNextPlan={hovered}- nextPlanLimit={nextPlan?.limits.clicks}- warning={warnings[0]}- />- <UsageRow- icon={Hyperlink}- label="Links"- usage={linksUsage}- limit={linksLimit}- showNextPlan={hovered}- nextPlanLimit={nextPlan?.limits.links}- warning={warnings[1]}- />- {salesLimit && salesLimit > 0 ? (+ <div className="mt-4 flex flex-col gap-4"><UsageRow- icon={CircleDollar}- label="Sales"- usage={salesUsage}- limit={salesLimit}+ icon={CursorRays}+ label="Events"+ usage={usage}+ limit={usageLimit}showNextPlan={hovered}- // nextPlanLimit={nextPlan?.limits.sales}- // TODO: Update this once we update the plan limits- nextPlanLimit={50000}- warning={warnings[2]}+ nextPlanLimit={nextPlan?.limits.clicks}+ warning={warnings[0]}/>- ) : null}- </div>+ <UsageRow+ icon={Hyperlink}+ label="Links"+ usage={linksUsage}+ limit={linksLimit}+ showNextPlan={hovered}+ nextPlanLimit={nextPlan?.limits.links}+ warning={warnings[1]}+ />+ {salesLimit && salesLimit > 0 ? (+ <UsageRow+ ref={setSalesRef}+ icon={CircleDollar}+ label="Sales"+ usage={salesUsage}+ limit={salesLimit}+ showNextPlan={hovered}+ // nextPlanLimit={nextPlan?.limits.sales}+ // TODO: Update this once we update the plan limits+ nextPlanLimit={50000}+ warning={warnings[2]}+ />+ ) : null}+ </div>- <div className="mt-3">- {loading ? (- <div className="h-4 w-2/3 animate-pulse rounded-md bg-neutral-500/10" />- ) : (- <p+ <div className="mt-3">+ {loading ? (+ <div className="h-4 w-2/3 animate-pulse rounded-md bg-neutral-500/10" />+ ) : (+ <p+ className={cn(+ "text-xs text-neutral-900/40",+ paymentFailedAt && "text-red-600",+ )}+ >+ {paymentFailedAt+ ? "Your last payment failed. Please update your payment method to continue using Dub."+ : `Usage will reset ${billingEnd}`}+ </p>+ )}+ </div>++ {paymentFailedAt ? (+ <ManageSubscriptionButton+ text="Update Payment Method"+ variant="primary"+ className="mt-4 w-full"+ onMouseEnter={() => {+ setHovered(true);+ }}+ onMouseLeave={() => {+ setHovered(false);+ }}+ />+ ) : warning || plan === "free" ? (+ <Link+ href={`/${slug}/upgrade`}className={cn(- "text-xs text-neutral-900/40",- paymentFailedAt && "text-red-600",+ buttonVariants(),+ "mt-4 flex h-9 items-center justify-center rounded-md border px-4 text-sm",)}+ onMouseEnter={() => {+ setHovered(true);+ }}+ onMouseLeave={() => {+ setHovered(false);+ }}>- {paymentFailedAt- ? "Your last payment failed. Please update your payment method to continue using Dub."- : `Usage will reset ${billingEnd}`}- </p>- )}+ {plan === "free" ? "Get Dub Pro" : "Upgrade plan"}+ </Link>+ ) : null}</div>-- {paymentFailedAt ? (- <ManageSubscriptionButton- text="Update Payment Method"- variant="primary"- className="mt-4 w-full"- onMouseEnter={() => {- setHovered(true);- }}- onMouseLeave={() => {- setHovered(false);- }}- />- ) : warning || plan === "free" ? (- <Link- href={`/${slug}/upgrade`}- className={cn(- buttonVariants(),- "mt-4 flex h-9 items-center justify-center rounded-md border px-4 text-sm",- )}- onMouseEnter={() => {- setHovered(true);- }}- onMouseLeave={() => {- setHovered(false);- }}- >- {plan === "free" ? "Get Dub Pro" : "Upgrade plan"}- </Link>- ) : null}- </div>- </AnimatedSizeContainer>+ </AnimatedSizeContainer>+ {showConversionOnboarding && !isMobile && (+ <ConversionOnboardingPopup reference={salesRef} />+ )}+ </>) : null;}-function UsageRow({- icon: Icon,- label,- usage,- limit,- showNextPlan,- nextPlanLimit,- warning,-}: {+type UsageRowProps = {icon: Icon;label: string;usage?: number;@@ -186,110 +206,127 @@ function UsageRow({showNextPlan: boolean;nextPlanLimit?: number;warning: boolean;-}) {- const loading = usage === undefined || limit === undefined;- const unlimited = limit !== undefined && limit >= INFINITY_NUMBER;+};- return (- <div>- <div className="flex items-center justify-between gap-2">- <div className="flex items-center gap-2">- <Icon className="size-3.5 text-neutral-600" />- <span className="text-xs font-medium text-neutral-700">{label}</span>- </div>- {!loading ? (- <div className="flex items-center">- <span className="text-xs font-medium text-neutral-600">- <NumberFlow- value={label === "Sales" ? usage / 100 : usage}- format={- label === "Sales"- ? {- style: "currency",- currency: "USD",- maximumFractionDigits: 0,- }- : undefined- }- />{" "}- of{" "}- <motion.span- className={cn(- "relative transition-colors duration-150",- showNextPlan && nextPlanLimit- ? "text-neutral-400"- : "text-neutral-600",- )}- >- {label === "Sales" ? "$" : ""}- {formatNumber(label === "Sales" ? limit / 100 : limit)}+const UsageRow = forwardRef<HTMLDivElement, UsageRowProps>(+ (+ {+ icon: Icon,+ label,+ usage,+ limit,+ showNextPlan,+ nextPlanLimit,+ warning,+ }: UsageRowProps,+ ref,+ ) => {+ const loading = usage === undefined || limit === undefined;+ const unlimited = limit !== undefined && limit >= INFINITY_NUMBER;++ return (+ <div ref={ref}>+ <div className="flex items-center justify-between gap-2">+ <div className="flex items-center gap-2">+ <Icon className="size-3.5 text-neutral-600" />+ <span className="text-xs font-medium text-neutral-700">+ {label}+ </span>+ </div>+ {!loading ? (+ <div className="flex items-center">+ <span className="text-xs font-medium text-neutral-600">+ <NumberFlow+ value={label === "Sales" ? usage / 100 : usage}+ format={+ label === "Sales"+ ? {+ style: "currency",+ currency: "USD",+ maximumFractionDigits: 0,+ }+ : undefined+ }+ />{" "}+ of{" "}+ <motion.span+ className={cn(+ "relative transition-colors duration-150",+ showNextPlan && nextPlanLimit+ ? "text-neutral-400"+ : "text-neutral-600",+ )}+ >+ {label === "Sales" ? "$" : ""}+ {formatNumber(label === "Sales" ? limit / 100 : limit)}+ {showNextPlan && nextPlanLimit && (+ <motion.span+ className="absolute bottom-[45%] left-0 h-[1px] bg-neutral-400"+ initial={{ width: "0%" }}+ animate={{ width: "100%" }}+ transition={{+ duration: 0.25,+ ease: "easeInOut",+ }}+ />+ )}+ </motion.span>+ </span>+ <AnimatePresence>{showNextPlan && nextPlanLimit && (- <motion.span- className="absolute bottom-[45%] left-0 h-[1px] bg-neutral-400"- initial={{ width: "0%" }}- animate={{ width: "100%" }}+ <motion.div+ className="flex items-center"+ initial={{ width: 0, opacity: 0 }}+ animate={{ width: "auto", opacity: 1 }}+ exit={{ width: 0, opacity: 0 }}transition={{duration: 0.25,- ease: "easeInOut",+ ease: [0.4, 0, 0.2, 1], // Custom cubic-bezier for smooth movement}}- />+ >+ <motion.span className="ml-1 whitespace-nowrap text-xs font-medium text-blue-600">+ {formatNumber(nextPlanLimit)}+ </motion.span>+ </motion.div>)}- </motion.span>- </span>- <AnimatePresence>- {showNextPlan && nextPlanLimit && (- <motion.div- className="flex items-center"- initial={{ width: 0, opacity: 0 }}- animate={{ width: "auto", opacity: 1 }}- exit={{ width: 0, opacity: 0 }}- transition={{- duration: 0.25,- ease: [0.4, 0, 0.2, 1], // Custom cubic-bezier for smooth movement- }}+ </AnimatePresence>+ </div>+ ) : (+ <div className="h-4 w-16 animate-pulse rounded-md bg-neutral-500/10" />+ )}+ </div>+ {!unlimited && (+ <div className="mt-1.5">+ <div+ className={cn(+ "h-0.5 w-full overflow-hidden rounded-full bg-neutral-900/10 transition-colors",+ loading && "bg-neutral-900/5",+ )}+ >+ {!loading && (+ <div+ className="animate-slide-right-fade size-full"+ style={{ "--offset": "-100%" } as CSSProperties}>- <motion.span className="ml-1 whitespace-nowrap text-xs font-medium text-blue-600">- {formatNumber(nextPlanLimit)}- </motion.span>- </motion.div>+ <div+ className={cn(+ "size-full rounded-full bg-gradient-to-r from-transparent to-blue-600",+ warning && "to-rose-500",+ )}+ style={{+ transform: `translateX(-${100 - Math.max(Math.floor((usage / Math.max(0, usage, limit)) * 100), usage === 0 ? 0 : 1)}%)`,+ transition: "transform 0.25s ease-in-out",+ }}+ />+ </div>)}- </AnimatePresence>+ </div></div>- ) : (- <div className="h-4 w-16 animate-pulse rounded-md bg-neutral-500/10" />)}</div>- {!unlimited && (- <div className="mt-1.5">- <div- className={cn(- "h-0.5 w-full overflow-hidden rounded-full bg-neutral-900/10 transition-colors",- loading && "bg-neutral-900/5",- )}- >- {!loading && (- <div- className="animate-slide-right-fade size-full"- style={{ "--offset": "-100%" } as CSSProperties}- >- <div- className={cn(- "size-full rounded-full bg-gradient-to-r from-transparent to-blue-600",- warning && "to-rose-500",- )}- style={{- transform: `translateX(-${100 - Math.max(Math.floor((usage / Math.max(0, usage, limit)) * 100), usage === 0 ? 0 : 1)}%)`,- transition: "transform 0.25s ease-in-out",- }}- />- </div>- )}- </div>- </div>- )}- </div>- );-}+ );+ },+);const formatNumber = (value: number) =>value >= INFINITY_NUMBER@@ -298,3 +335,112 @@ const formatNumber = (value: number) =>full: value !== undefined && value < 99999,digits: 1,});++function ConversionOnboardingPopup({+ reference,+}: {+ reference: HTMLDivElement | null;+}) {+ const arrowRef = useRef<SVGSVGElement>(null);++ const { refs, floatingStyles, context } = useFloating({+ placement: "right-end",+ strategy: "fixed",+ whileElementsMounted(referenceEl, floatingEl, update) {+ const cleanup = autoUpdate(referenceEl, floatingEl, update, {+ // Not good for performance but keeps the arrow and floating element in the right spot+ animationFrame: true,+ });+ return cleanup;+ },+ elements: {+ reference,+ },+ middleware: [+ offset({+ mainAxis: 32,+ crossAxis: 7,+ }),+ shift({+ padding: 32,+ }),+ arrow({+ element: arrowRef,+ }),+ ],+ });++ const dismiss = () => {};++ return (+ <FloatingPortal>+ <div+ ref={refs.setFloating}+ style={floatingStyles}+ className="drop-shadow-sm"+ >+ <div className="animate-slide-up-fade relative flex w-[244px] flex-col rounded-lg border border-neutral-200 bg-white p-3 text-left">+ <div className="relative">+ <Link+ href="https://dub.co/help/article/dub-conversions"+ target="_blank"+ className="group relative flex aspect-video w-full items-center justify-center overflow-hidden rounded-md border border-neutral-200 bg-neutral-100"+ >+ {/* TODO: Add video thumbnail */}+ {/* <Image+ src=""+ alt="Video thumbnail"+ fill+ className="object-cover"+ /> */}+ <div className="relative flex size-10 items-center justify-center rounded-full bg-neutral-900 ring-[6px] ring-black/5 transition-all duration-75 group-hover:ring-[8px] group-active:ring-[7px]">+ <Play className="size-4 fill-current text-white" />+ </div>+ </Link>+ <button+ type="button"+ onClick={dismiss}+ className="absolute right-2 top-2 rounded-md border border-neutral-200 bg-white p-1.5 shadow-sm transition-colors duration-75 hover:bg-neutral-50"+ >+ <X className="size-4 text-neutral-500" />+ </button>+ </div>+ <h2 className="mt-4 text-sm font-semibold text-neutral-700">+ Conversion tracking unlocked+ </h2>+ <p className="mt-1.5 text-xs text-neutral-500">+ Follow our guides to get set up and track your short link+ conversions+ </p>+ <div className="mt-4 grid w-full grid-cols-2 gap-2">+ <Button+ type="button"+ variant="secondary"+ className="h-7 text-xs"+ text="Maybe later"+ onClick={dismiss}+ />+ <Link+ href={`https://dub.co/help/article/dub-conversions`}+ target="_blank"+ className={cn(+ buttonVariants({ variant: "primary" }),+ "flex h-7 items-center justify-center whitespace-nowrap rounded-lg border px-3 text-sm text-xs",+ )}+ >+ View guides+ </Link>+ </div>+ <FloatingArrow+ ref={arrowRef}+ context={context}+ className="stroke-neutral-200"+ fill="white"+ strokeWidth={1}+ height={10}+ />+ </div>+ </div>+ </FloatingPortal>+ );+}diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prismaindex a1bea390c8..fcfa818c39 100644--- a/packages/prisma/schema/workspace.prisma+++ b/packages/prisma/schema/workspace.prisma@@ -29,6 +29,8 @@ model Project {referralLinkId String? @uniquereferredSignups Int @default(0)+ store Json @default("{}") // General key-value store for things like persisting toggles, dismissing popups, etc.+webhookEnabled Boolean @default(false)conversionEnabled Boolean @default(false) // TODO: remove this once Conversions goes GApartnersEnabled Boolean @default(false)diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 576c20ccdb..7fb60f7ea2 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -63,6 +63,9 @@ importers:'@dub/utils':specifier: workspace:*version: link:../../packages/utils+ '@floating-ui/react':+ specifier: ^0.26.20+ version: 0.26.20([email protected])([email protected])'@hookform/resolvers':specifier: ^3.9.0version: 3.9.0([email protected])@@ -4310,16 +4313,12 @@ packages:react-dom: '>=16.8.0'dependencies:'@floating-ui/react-dom': 2.1.1([email protected])([email protected])- '@floating-ui/utils': 0.2.5+ '@floating-ui/utils': 0.2.8react: 18.2.0react-dom: 18.2.0([email protected])tabbable: 6.2.0dev: false- /@floating-ui/[email protected]:- resolution: {integrity: sha512-sTcG+QZ6fdEUObICavU+aB3Mp8HY4n14wYHdxK4fXjPmv3PXZZeY5RaguJmGyeH/CJQhX3fqKUtS4qc1LoHwhQ==}- dev: false-/@floating-ui/[email protected]:resolution: {integrity: sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==}dev: false