The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add conversion tracking toggle to link builder
Tim Wilsonbd99e9eaebea
diff --git a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsxindex 1e82ae1392..cf58630304 100644--- a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx+++ b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx@@ -1,4 +1,13 @@-import { InfoTooltip, SimpleTooltipContent, Switch } from "@dub/ui";+import useWorkspace from "@/lib/swr/use-workspace";+import {+ CrownSmall,+ InfoTooltip,+ SimpleTooltipContent,+ Switch,+ Tooltip,+ useKeyboardShortcut,+} from "@dub/ui";+import { PropsWithChildren } from "react";import { useFormContext } from "react-hook-form";import { LinkFormData } from ".";@@ -7,13 +16,27 @@ const isNew =new Date().getTime() - new Date("2025-01-13").getTime() < 30 * 86_400_000;export function ConversionTrackingToggle() {+ const { plan } = useWorkspace();const { watch, setValue } = useFormContext<LinkFormData>();+ const conversionsEnabled = !!plan && plan !== "free" && plan !== "pro";+const trackConversion = watch("trackConversion");+ useKeyboardShortcut(+ "c",+ () => setValue("trackConversion", !trackConversion),+ { modal: true, enabled: conversionsEnabled },+ );+return (<label className="flex items-center justify-between"><div className="flex items-center gap-2">+ {isNew && (+ <div className="rounded-full border border-green-200 bg-green-100 px-2 py-0.5 text-[0.625rem] uppercase leading-none text-green-900">+ New+ </div>+ )}<span className="flex select-none items-center gap-1 text-sm font-medium text-gray-700">Enable Conversion Tracking<InfoTooltip@@ -27,14 +50,35 @@ export function ConversionTrackingToggle() {/></span></div>- <Switch- checked={trackConversion}- fn={(checked) =>- setValue("trackConversion", checked, {- shouldDirty: true,- })- }- />+ <DisabledTooltip disabled={!conversionsEnabled}>+ <Switch+ checked={trackConversion}+ fn={(checked) =>+ setValue("trackConversion", checked, {+ shouldDirty: true,+ })+ }+ disabled={!conversionsEnabled}+ thumbIcon={+ conversionsEnabled ? undefined : (+ <CrownSmall className="size-full text-neutral-500" />+ )+ }+ />+ </DisabledTooltip></label>);}++function DisabledTooltip({+ children,+ disabled,+}: PropsWithChildren<{ disabled: boolean }>) {+ return disabled ? (+ <Tooltip content="Requires a Dub Business Plan to enable">+ <div>{children}</div>+ </Tooltip>+ ) : (+ children+ );+}diff --git a/packages/ui/src/icons/crown-small.tsx b/packages/ui/src/icons/crown-small.tsxnew file mode 100644index 0000000000..14a586bd21--- /dev/null+++ b/packages/ui/src/icons/crown-small.tsx@@ -0,0 +1,23 @@+import { SVGProps } from "react";++export function CrownSmall(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="13"+ height="14"+ fill="none"+ viewBox="0 0 13 14"+ {...props}+ >+ <path+ fill="currentColor"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.03"+ d="m9.748 9.402.396-4.275-1.91 1.933-1.73-3.146-1.73 3.146-2.18-1.933.667 4.275a.63.63 0 0 0 .617.512H9.13a.63.63 0 0 0 .619-.512"+ />+ </svg>+ );+}diff --git a/packages/ui/src/icons/index.tsx b/packages/ui/src/icons/index.tsxindex 06306f275e..c3d1a34036 100644--- a/packages/ui/src/icons/index.tsx+++ b/packages/ui/src/icons/index.tsx@@ -5,6 +5,7 @@ import { ComponentType, SVGProps } from "react";// custom iconsexport { default as Copy } from "./copy";+export * from "./crown-small";export { default as ExpandingArrow } from "./expanding-arrow";export { default as Magic } from "./magic";export * from "./matrix-lines";diff --git a/packages/ui/src/switch.tsx b/packages/ui/src/switch.tsxindex 9a79d07a17..9377a3076e 100644--- a/packages/ui/src/switch.tsx+++ b/packages/ui/src/switch.tsx@@ -11,6 +11,7 @@ export function Switch({trackDimensions,thumbDimensions,thumbTranslate,+ thumbIcon,checked = true,loading = false,disabled = false,@@ -21,6 +22,7 @@ export function Switch({trackDimensions?: string;thumbDimensions?: string;thumbTranslate?: string;+ thumbIcon?: ReactNode;checked?: boolean;loading?: boolean;disabled?: boolean;@@ -52,7 +54,9 @@ export function Switch({thumbDimensions,thumbTranslate,)}- />+ >+ {thumbIcon}+ </SwitchPrimitive.Thumb></SwitchPrimitive.Root>);