Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add basic toggle

Tim Wilson4f0528ad3a4e
diff --git a/apps/web/ui/links/short-link-input.tsx b/apps/web/ui/links/short-link-input.tsx
index 1a97a2533d..973ae80a4e 100644
--- a/apps/web/ui/links/short-link-input.tsx
+++ b/apps/web/ui/links/short-link-input.tsx
@@ -370,7 +370,8 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
onChange={(domain) => onChange({ domain })}
/>
)}
- {!onboarding && !dotLinkClaimed && (
+ {/* Hidden for now to make room for the conversion tracking toggle */}
+ {!onboarding && !dotLinkClaimed && false && (
<AnimatedSizeContainer
height
transition={{ ease: "linear", duration: 0.1 }}
diff --git a/apps/web/ui/modals/link-builder/constants.ts b/apps/web/ui/modals/link-builder/constants.ts
index c43c1fb7ad..f462ea43eb 100644
--- a/apps/web/ui/modals/link-builder/constants.ts
+++ b/apps/web/ui/modals/link-builder/constants.ts
@@ -4,7 +4,6 @@ import {
Crosshairs3,
Incognito,
InputPassword,
- SquareChart,
WindowSearch,
} from "@dub/ui/icons";
import { UseFormSetValue } from "react-hook-form";
@@ -24,16 +23,6 @@ export const TOGGLES = [
shortcutKey: "k",
type: "boolean",
},
- {
- key: "trackConversion",
- icon: SquareChart,
- label: "Conversion Tracking",
- description:
- "Track conversions on your short link to measure the effectiveness of your marketing campaigns.",
- learnMoreUrl: "https://dub.co/help/article/conversion-tracking",
- shortcutKey: "c",
- type: "boolean",
- },
{
key: "doIndex",
icon: WindowSearch,
diff --git a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
new file mode 100644
index 0000000000..1e82ae1392
--- /dev/null
+++ b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
@@ -0,0 +1,40 @@
+import { InfoTooltip, SimpleTooltipContent, Switch } from "@dub/ui";
+import { useFormContext } from "react-hook-form";
+import { LinkFormData } from ".";
+
+// Show new badge for 30 days
+const isNew =
+ new Date().getTime() - new Date("2025-01-13").getTime() < 30 * 86_400_000;
+
+export function ConversionTrackingToggle() {
+ const { watch, setValue } = useFormContext<LinkFormData>();
+
+ const trackConversion = watch("trackConversion");
+
+ return (
+ <label className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <span className="flex select-none items-center gap-1 text-sm font-medium text-gray-700">
+ Enable Conversion Tracking
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title="View analytics on conversions from your short links."
+ cta="Learn more."
+ href="https://dub.co/docs/conversions/quickstart"
+ />
+ }
+ />
+ </span>
+ </div>
+ <Switch
+ checked={trackConversion}
+ fn={(checked) =>
+ setValue("trackConversion", checked, {
+ shouldDirty: true,
+ })
+ }
+ />
+ </label>
+ );
+}
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index 3219d28cff..bc51439f9e 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -52,6 +52,7 @@ import TextareaAutosize from "react-textarea-autosize";
import { toast } from "sonner";
import { mutate } from "swr";
import { useDebounce } from "use-debounce";
+import { ConversionTrackingToggle } from "./conversion-tracking-toggle";
import { DraftControls, DraftControlsHandle } from "./draft-controls";
import { useExpirationModal } from "./expiration-modal";
import { LinkPreview } from "./link-preview";
@@ -116,7 +117,7 @@ function LinkBuilderInner({
const { slug } = params;
const searchParams = useSearchParams();
const { queryParams } = useRouterStuff();
- const { id: workspaceId, plan, nextPlan, logo, flags } = useWorkspace();
+ const { id: workspaceId, plan, nextPlan, logo } = useWorkspace();
const {
control,
@@ -131,12 +132,13 @@ function LinkBuilderInner({
const formRef = useRef<HTMLFormElement>(null);
const { handleKeyDown } = useEnterSubmit(formRef);
- const [url, domain, key, title, description] = watch([
+ const [url, domain, key, title, description, trackConversion] = watch([
"url",
"domain",
"key",
"title",
"description",
+ "trackConversion",
]);
const [debouncedUrl] = useDebounce(getUrlWithoutUTMParams(url), 500);
@@ -369,7 +371,7 @@ function LinkBuilderInner({
)}
>
<div className="scrollbar-hide px-6 md:overflow-auto">
- <div className="flex min-h-full flex-col gap-8 py-4">
+ <div className="flex min-h-full flex-col gap-6 py-4">
<Controller
name="url"
control={control}
@@ -464,6 +466,8 @@ function LinkBuilderInner({
/>
</div>
+ <ConversionTrackingToggle />
+
<div className="flex grow flex-col justify-end">
<OptionsList />
</div>