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 limits/restrictions

Tim Wilsonb6de21823320
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 72e3ad78bc..2e7a90440b 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -289,8 +289,8 @@ export async function processLink<T extends Record<string, any>>({
}
}
- if (trackConversion) {
- if (!workspace || workspace.plan === "free" || workspace.plan === "pro") {
+ if (!workspace || workspace.plan === "free" || workspace.plan === "pro") {
+ if (trackConversion) {
return {
link: payload,
error:
@@ -298,6 +298,23 @@ export async function processLink<T extends Record<string, any>>({
code: "forbidden",
};
}
+
+ if (tests) {
+ return {
+ link: payload,
+ error:
+ "A/B testing is only available for workspaces with a Business plan and above. Please upgrade to continue.",
+ code: "forbidden",
+ };
+ }
+ }
+
+ if (!trackConversion && tests) {
+ return {
+ link: payload,
+ error: "Conversion tracking must be enabled to use A/B testing.",
+ code: "unprocessable_entity",
+ };
}
if (externalId && workspace && !skipExternalIdChecks) {
diff --git a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
index 7866cdb76d..2a9bc91e0a 100644
--- a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
+++ b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
@@ -4,6 +4,7 @@ import {
MIN_TEST_PERCENTAGE,
} from "@/lib/zod/schemas/links";
import { useAvailableDomains } from "@/ui/links/use-available-domains";
+import { BusinessBadgeTooltip } from "@/ui/shared/business-badge-tooltip";
import { X } from "@/ui/shared/icons";
import {
AnimatedSizeContainer,
@@ -222,6 +223,7 @@ function ABTestingModal({
}
setValueParent("url", currentTests[0].url, { shouldDirty: true });
+ setValueParent("trackConversion", true);
setValueParent("tests", currentTests, { shouldDirty: true });
setValueParent("testsCompleteAt", data.testsCompleteAt, {
shouldDirty: true,
@@ -233,7 +235,7 @@ function ABTestingModal({
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<h3 className="text-lg font-medium">A/B Testing</h3>
- <InfoTooltip
+ <BusinessBadgeTooltip
content={
<SimpleTooltipContent
title="Test different URLs against each other to optimize your conversion rates."
diff --git a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
index 5c2d3a592d..ea8a672e19 100644
--- a/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
+++ b/apps/web/ui/modals/link-builder/conversion-tracking-toggle.tsx
@@ -1,6 +1,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import {
CrownSmall,
+ FlaskSmall,
InfoTooltip,
SimpleTooltipContent,
Switch,
@@ -20,7 +21,7 @@ export function ConversionTrackingToggle() {
const conversionsEnabled = !!plan && plan !== "free" && plan !== "pro";
- const trackConversion = watch("trackConversion");
+ const [trackConversion, tests] = watch(["trackConversion", "tests"]);
useKeyboardShortcut(
"c",
@@ -57,7 +58,9 @@ export function ConversionTrackingToggle() {
})
}
disabledTooltip={
- conversionsEnabled ? undefined : (
+ trackConversion && tests ? (
+ <TooltipContent title="Conversion tracking must be enabled to use A/B testing." />
+ ) : conversionsEnabled ? undefined : (
<TooltipContent
title="Conversion tracking is only available on Business plans and above."
cta="Upgrade to Business"
@@ -69,7 +72,11 @@ export function ConversionTrackingToggle() {
)
}
thumbIcon={
- conversionsEnabled ? undefined : (
+ trackConversion && tests ? (
+ <span className="flex size-full items-center justify-center">
+ <FlaskSmall className="size-2 text-blue-500" />
+ </span>
+ ) : conversionsEnabled ? undefined : (
<CrownSmall className="size-full text-neutral-500" />
)
}
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index ce4ec49c06..79c0fbdd63 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -122,6 +122,7 @@ function LinkBuilderInner({
const searchParams = useSearchParams();
const { queryParams } = useRouterStuff();
const { id: workspaceId, plan, nextPlan, logo, flags } = useWorkspace();
+ const conversionsEnabled = !!plan && plan !== "free" && plan !== "pro";
const {
control,
@@ -222,7 +223,7 @@ function LinkBuilderInner({
<>
<UTMModal />
<TargetingModal />
- <ABTestingModal />
+ {conversionsEnabled && <ABTestingModal />}
<PasswordModal />
<ExpirationModal />
<Modal
@@ -523,7 +524,7 @@ function LinkBuilderInner({
<UTMButton />
<div className="flex items-center gap-2 max-sm:hidden">
<TargetingButton />
- <ABTestingButton />
+ {conversionsEnabled && <ABTestingButton />}
<PasswordButton />
<ExpirationButton />
</div>
diff --git a/apps/web/ui/shared/business-badge-tooltip.tsx b/apps/web/ui/shared/business-badge-tooltip.tsx
new file mode 100644
index 0000000000..dbdbad6d94
--- /dev/null
+++ b/apps/web/ui/shared/business-badge-tooltip.tsx
@@ -0,0 +1,24 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { BadgeTooltip, InfoTooltip, type TooltipProps } from "@dub/ui";
+import { Crown } from "lucide-react";
+
+/**
+ * A dynamic badge/icon w/ tooltip based on the workspace plan:
+ *
+ * For a free or Pro workspace: a "Business" badge
+ * For a Business workspace: an info icon (question mark circle)
+ */
+export function BusinessBadgeTooltip(props: Omit<TooltipProps, "children">) {
+ const { plan } = useWorkspace();
+
+ return ["free", "pro"].includes(plan!) ? (
+ <BadgeTooltip {...props}>
+ <div className="flex items-center space-x-1">
+ <Crown size={12} />
+ <p className="uppercase">Business</p>
+ </div>
+ </BadgeTooltip>
+ ) : (
+ <InfoTooltip {...props} />
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/flask-small.tsx b/packages/ui/src/icons/nucleo/flask-small.tsx
new file mode 100644
index 0000000000..5bcfbf24d8
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/flask-small.tsx
@@ -0,0 +1,35 @@
+import { SVGProps } from "react";
+
+export function FlaskSmall(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="12"
+ width="12"
+ viewBox="0 0 12 12"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="m4.25.75v5.25l-2.464,3.695c-.443.665.033,1.555.832,1.555h6.763c.799,0,1.275-.89.832-1.555l-2.464-3.695V.75"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="3.25"
+ x2="8.75"
+ y1=".75"
+ y2=".75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 12b7bb3d6d..bff2c1afc7 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -84,6 +84,7 @@ export * from "./flag-wavy";
export * from "./flag2";
export * from "./flag6";
export * from "./flask";
+export * from "./flask-small";
export * from "./folder";
export * from "./folder-bookmark";
export * from "./folder-lock";