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.

reuse welcome modal

Steven Teyf0ce814bdec6
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
index 8ab8fbc6ea..cde20e1f84 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
@@ -23,13 +23,11 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {
})
: null;
- const returnUrl = new URL(baseUrl);
-
// if the user already has a subscription, create billing portal to upgrade
if (workspace.stripeId && subscription && subscription.data.length > 0) {
const { url } = await stripe.billingPortal.sessions.create({
customer: workspace.stripeId,
- return_url: returnUrl.toString(),
+ return_url: baseUrl,
flow_data: comparePlans
? {
type: "subscription_update",
@@ -57,14 +55,14 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {
// if the user does not have a subscription, create a new checkout session
} else {
const successUrl = onboarding
- ? `${APP_DOMAIN}/${workspace.slug}?onboarded=true&plan=${plan}`
- : `${APP_DOMAIN}/${workspace.slug}/settings/billing?success=true&plan=${plan}&period=${period}`;
+ ? `${APP_DOMAIN}/${workspace.slug}?onboarded=true&plan=${plan}&period=${period}`
+ : `${baseUrl}?upgraded=true&plan=${plan}&period=${period}`;
const stripeSession = await stripe.checkout.sessions.create({
customer_email: session.user.email,
billing_address_collection: "required",
success_url: successUrl,
- cancel_url: returnUrl.toString(),
+ cancel_url: baseUrl,
line_items: [{ price: prices.data[0].id, quantity: 1 }],
automatic_tax: {
enabled: true,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
index 2c5352495e..f4c6ec04f5 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
@@ -6,21 +6,11 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { Divider } from "@/ui/shared/icons";
import Infinity from "@/ui/shared/icons/infinity";
import PlanBadge from "@/ui/workspaces/plan-badge";
-import {
- Button,
- buttonVariants,
- InfoTooltip,
- ProgressBar,
- useRouterStuff,
-} from "@dub/ui";
-import { cn, getFirstAndLastDay, getPlanDetails, nFormatter } from "@dub/utils";
-import { trackEvent } from "fathom-client";
-import { usePlausible } from "next-plausible";
+import { Button, buttonVariants, InfoTooltip, ProgressBar } from "@dub/ui";
+import { cn, getFirstAndLastDay, nFormatter } from "@dub/utils";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
-import posthog from "posthog-js";
-import { useEffect, useMemo, useState } from "react";
-import Confetti from "react-dom-confetti";
+import { useMemo, useState } from "react";
import { toast } from "sonner";
export default function WorkspaceBillingClient() {
@@ -28,7 +18,7 @@ export default function WorkspaceBillingClient() {
const searchParams = useSearchParams();
const {
- id,
+ id: workspaceId,
slug,
plan,
stripeId,
@@ -68,195 +58,165 @@ export default function WorkspaceBillingClient() {
return [];
}, [billingCycleStart]);
- const { queryParams } = useRouterStuff();
- const [confetti, setConfetti] = useState(false);
-
- const plausible = usePlausible();
-
- useEffect(() => {
- if (searchParams?.get("success")) {
- setConfetti(true);
- const plan = searchParams.get("plan");
- const period = searchParams.get("period");
- const currentPlan = plan ? getPlanDetails(plan) : undefined;
- toast.success(`Successfully upgraded to ${currentPlan?.name || plan}!`);
- if (currentPlan && period) {
- // track upgrade event
- trackEvent(`Upgraded to ${currentPlan.name}`, {
- _value: currentPlan.price[period] * 100, // in cents
- });
- plausible(`Upgraded to ${currentPlan.name}`);
- posthog.capture("plan_upgraded", {
- plan: currentPlan.name,
- period,
- revenue: currentPlan.price[period],
- });
- }
- }
- }, [searchParams, plan]);
-
return (
- <>
- <Confetti active={confetti} config={{ elementCount: 200, spread: 90 }} />
- <div className="-mt-5 rounded-lg border border-gray-200 bg-white">
- <div className="flex flex-col items-start justify-between space-y-4 p-10 xl:flex-row xl:space-y-0">
- <div className="flex flex-col space-y-3">
- <h2 className="text-xl font-medium">Plan &amp; Usage</h2>
- <p className="text-sm text-gray-500">
- You are currently on the{" "}
- {plan ? (
- <PlanBadge plan={plan} />
- ) : (
- <span className="rounded-full bg-gray-200 px-2 py-0.5 text-xs text-gray-200">
- load
+ <div className="-mt-5 rounded-lg border border-gray-200 bg-white">
+ <div className="flex flex-col items-start justify-between space-y-4 p-10 xl:flex-row xl:space-y-0">
+ <div className="flex flex-col space-y-3">
+ <h2 className="text-xl font-medium">Plan &amp; Usage</h2>
+ <p className="text-sm text-gray-500">
+ You are currently on the{" "}
+ {plan ? (
+ <PlanBadge plan={plan} />
+ ) : (
+ <span className="rounded-full bg-gray-200 px-2 py-0.5 text-xs text-gray-200">
+ load
+ </span>
+ )}{" "}
+ plan.
+ {billingStart && billingEnd && (
+ <>
+ {" "}
+ Current billing cycle:{" "}
+ <span className="font-medium text-black">
+ {billingStart} - {billingEnd}
</span>
- )}{" "}
- plan.
- {billingStart && billingEnd && (
- <>
- {" "}
- Current billing cycle:{" "}
- <span className="font-medium text-black">
- {billingStart} - {billingEnd}
- </span>
- .
- </>
- )}
- </p>
- </div>
- {stripeId && (
- <div>
- <Button
- text="Manage Subscription"
- variant="secondary"
- className="h-9"
- onClick={() => {
- setClicked(true);
- fetch(`/api/workspaces/${id}/billing/manage`, {
- method: "POST",
- }).then(async (res) => {
- if (res.ok) {
- const url = await res.json();
- console.log({ url });
- router.push(url);
- } else {
- const { error } = await res.json();
- toast.error(error.message);
- setClicked(false);
- }
- });
- }}
- loading={clicked}
- />
- </div>
- )}
- </div>
- <div className="grid divide-y divide-gray-200 border-y border-gray-200">
- <div
- className={cn(
- "grid grid-cols-1 divide-y divide-gray-200",
- conversionEnabled && "sm:grid-cols-2 sm:divide-x sm:divide-y-0",
- )}
- >
- {conversionEnabled && (
- <UsageCategory
- title="Revenue tracked"
- unit="$"
- tooltip="Amount of revenue tracked for your current billing cycle."
- usage={salesUsage}
- usageLimit={salesLimit}
- />
+ .
+ </>
)}
- <UsageCategory
- title={conversionEnabled ? "Events tracked" : "Link Clicks"}
- unit={conversionEnabled ? "events" : "clicks"}
- tooltip={
- conversionEnabled
- ? "Number of events tracked for your current billing cycle (clicks, leads, sales)"
- : "Number of billable link clicks for your current billing cycle. If you exceed your monthly limits, your existing links will still work and clicks will still be tracked, but you need to upgrade to view your analytics."
- }
- usage={usage}
- usageLimit={usageLimit}
- numberOnly={(usageLimit && usageLimit >= 1000000000) || false}
- />
- </div>
- <div className="grid grid-cols-1 divide-y divide-gray-200 sm:grid-cols-2 sm:divide-x sm:divide-y-0">
- <UsageCategory
- title="Links Created"
- unit="links"
- tooltip="Number of short links created in the current billing cycle."
- usage={linksUsage}
- usageLimit={linksLimit}
- numberOnly={(linksLimit && linksLimit >= 1000000000) || false}
- />
- <UsageCategory
- title="Custom Domains"
- unit="domains"
- tooltip="Number of custom domains added to your workspace."
- usage={domains?.length}
- usageLimit={domainsLimit}
- numberOnly
+ </p>
+ </div>
+ {stripeId && (
+ <div>
+ <Button
+ text="Manage Subscription"
+ variant="secondary"
+ className="h-9"
+ onClick={() => {
+ setClicked(true);
+ fetch(`/api/workspaces/${workspaceId}/billing/manage`, {
+ method: "POST",
+ }).then(async (res) => {
+ if (res.ok) {
+ const url = await res.json();
+ console.log({ url });
+ router.push(url);
+ } else {
+ const { error } = await res.json();
+ toast.error(error.message);
+ setClicked(false);
+ }
+ });
+ }}
+ loading={clicked}
/>
</div>
- <div className="grid grid-cols-1 divide-y divide-gray-200 sm:grid-cols-2 sm:divide-x sm:divide-y-0">
- <UsageCategory
- title="Tags"
- unit="tags"
- tooltip="Number of tags added to your workspace."
- usage={tags?.length}
- usageLimit={tagsLimit}
- numberOnly
- />
+ )}
+ </div>
+ <div className="grid divide-y divide-gray-200 border-y border-gray-200">
+ <div
+ className={cn(
+ "grid grid-cols-1 divide-y divide-gray-200",
+ conversionEnabled && "sm:grid-cols-2 sm:divide-x sm:divide-y-0",
+ )}
+ >
+ {conversionEnabled && (
<UsageCategory
- title="Teammates"
- unit="users"
- tooltip="Number of users added to your workspace."
- usage={users?.filter((user) => !user.isMachine).length}
- usageLimit={usersLimit}
- numberOnly
+ title="Revenue tracked"
+ unit="$"
+ tooltip="Amount of revenue tracked for your current billing cycle."
+ usage={salesUsage}
+ usageLimit={salesLimit}
/>
- </div>
+ )}
+ <UsageCategory
+ title={conversionEnabled ? "Events tracked" : "Link Clicks"}
+ unit={conversionEnabled ? "events" : "clicks"}
+ tooltip={
+ conversionEnabled
+ ? "Number of events tracked for your current billing cycle (clicks, leads, sales)"
+ : "Number of billable link clicks for your current billing cycle. If you exceed your monthly limits, your existing links will still work and clicks will still be tracked, but you need to upgrade to view your analytics."
+ }
+ usage={usage}
+ usageLimit={usageLimit}
+ numberOnly={(usageLimit && usageLimit >= 1000000000) || false}
+ />
+ </div>
+ <div className="grid grid-cols-1 divide-y divide-gray-200 sm:grid-cols-2 sm:divide-x sm:divide-y-0">
+ <UsageCategory
+ title="Links Created"
+ unit="links"
+ tooltip="Number of short links created in the current billing cycle."
+ usage={linksUsage}
+ usageLimit={linksLimit}
+ numberOnly={(linksLimit && linksLimit >= 1000000000) || false}
+ />
+ <UsageCategory
+ title="Custom Domains"
+ unit="domains"
+ tooltip="Number of custom domains added to your workspace."
+ usage={domains?.length}
+ usageLimit={domainsLimit}
+ numberOnly
+ />
+ </div>
+ <div className="grid grid-cols-1 divide-y divide-gray-200 sm:grid-cols-2 sm:divide-x sm:divide-y-0">
+ <UsageCategory
+ title="Tags"
+ unit="tags"
+ tooltip="Number of tags added to your workspace."
+ usage={tags?.length}
+ usageLimit={tagsLimit}
+ numberOnly
+ />
+ <UsageCategory
+ title="Teammates"
+ unit="users"
+ tooltip="Number of users added to your workspace."
+ usage={users?.filter((user) => !user.isMachine).length}
+ usageLimit={usersLimit}
+ numberOnly
+ />
</div>
- <div className="flex flex-col items-center justify-between space-y-3 px-10 py-4 text-center md:flex-row md:space-y-0 md:text-left">
+ </div>
+ <div className="flex flex-col items-center justify-between space-y-3 px-10 py-4 text-center md:flex-row md:space-y-0 md:text-left">
+ {plan ? (
+ <p className="text-sm text-gray-500">
+ {plan === "enterprise"
+ ? "You're on the Enterprise plan."
+ : plan === "business max"
+ ? "Need more clicks or links? Contact us for an Enterprise quote."
+ : `For higher limits, upgrade to the ${nextPlan.name} plan.`}
+ </p>
+ ) : (
+ <div className="h-3 w-28 animate-pulse rounded-full bg-gray-200" />
+ )}
+ <div>
{plan ? (
- <p className="text-sm text-gray-500">
- {plan === "enterprise"
- ? "You're on the Enterprise plan."
- : plan === "business max"
- ? "Need more clicks or links? Contact us for an Enterprise quote."
- : `For higher limits, upgrade to the ${nextPlan.name} plan.`}
- </p>
+ plan === "enterprise" || plan === "business max" ? (
+ <a
+ href="https://dub.co/enterprise"
+ target="_blank"
+ className="inline-flex items-center justify-center rounded-md border border-violet-600 bg-violet-600 px-4 py-2 text-sm font-medium text-white transition-all hover:bg-white hover:text-violet-600 focus:outline-none"
+ >
+ Contact Sales
+ </a>
+ ) : (
+ <Link
+ href={`/${slug}/upgrade`}
+ className={cn(
+ buttonVariants(),
+ "flex h-9 w-full items-center justify-center rounded-md border px-4 text-sm",
+ )}
+ >
+ Upgrade to {nextPlan.name}
+ </Link>
+ )
) : (
- <div className="h-3 w-28 animate-pulse rounded-full bg-gray-200" />
+ <div className="h-10 w-24 animate-pulse rounded-md bg-gray-200" />
)}
- <div>
- {plan ? (
- plan === "enterprise" || plan === "business max" ? (
- <a
- href="https://dub.co/enterprise"
- target="_blank"
- className="inline-flex items-center justify-center rounded-md border border-violet-600 bg-violet-600 px-4 py-2 text-sm font-medium text-white transition-all hover:bg-white hover:text-violet-600 focus:outline-none"
- >
- Contact Sales
- </a>
- ) : (
- <Link
- href={`/${slug}/upgrade`}
- className={cn(
- buttonVariants(),
- "flex h-9 w-full items-center justify-center rounded-md border px-4 text-sm",
- )}
- >
- Upgrade to {nextPlan.name}
- </Link>
- )
- ) : (
- <div className="h-10 w-24 animate-pulse rounded-md bg-gray-200" />
- )}
- </div>
</div>
</div>
- </>
+ </div>
);
}
diff --git a/apps/web/ui/modals/modal-provider.tsx b/apps/web/ui/modals/modal-provider.tsx
index a75098f031..f26281f7f2 100644
--- a/apps/web/ui/modals/modal-provider.tsx
+++ b/apps/web/ui/modals/modal-provider.tsx
@@ -101,16 +101,24 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
const { setShowImportCsvModal, ImportCsvModal } = useImportCsvModal();
const { setShowWelcomeModal, WelcomeModal } = useWelcomeModal();
+ useEffect(
+ () =>
+ setShowWelcomeModal(
+ searchParams.has("onboarded") || searchParams.has("upgraded"),
+ ),
+ [searchParams],
+ );
+
const [hashes, setHashes] = useCookies<SimpleLinkProps[]>("hashes__dub", [], {
domain: !!process.env.NEXT_PUBLIC_VERCEL_URL ? ".dub.co" : undefined,
});
- const { id, error } = useWorkspace();
+ const { id: workspaceId, error } = useWorkspace();
useEffect(() => {
- if (hashes.length > 0 && id) {
+ if (hashes.length > 0 && workspaceId) {
toast.promise(
- fetch(`/api/links/sync?workspaceId=${id}`, {
+ fetch(`/api/links/sync?workspaceId=${workspaceId}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -133,7 +141,7 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
},
);
}
- }, [hashes, id]);
+ }, [hashes, workspaceId]);
// handle invite and oauth modals
useEffect(() => {
diff --git a/apps/web/ui/modals/welcome-modal.tsx b/apps/web/ui/modals/welcome-modal.tsx
index 0a64178c18..68f219dde3 100644
--- a/apps/web/ui/modals/welcome-modal.tsx
+++ b/apps/web/ui/modals/welcome-modal.tsx
@@ -5,9 +5,11 @@ import {
useRouterStuff,
useScrollProgress,
} from "@dub/ui";
-import { cn, PLANS, PRO_PLAN } from "@dub/utils";
+import { cn, getPlanDetails, PLANS, PRO_PLAN } from "@dub/utils";
+import { usePlausible } from "next-plausible";
import Image from "next/image";
import { useSearchParams } from "next/navigation";
+import posthog from "posthog-js";
import {
Dispatch,
SetStateAction,
@@ -33,6 +35,23 @@ function WelcomeModal({
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const planId = searchParams.get("plan");
+ const upgraded = searchParams.get("upgraded");
+ const plausible = usePlausible();
+
+ useEffect(() => {
+ if (planId) {
+ const currentPlan = getPlanDetails(planId);
+ const period = searchParams.get("period");
+ if (currentPlan && period) {
+ plausible(`Upgraded to ${currentPlan.name}`);
+ posthog.capture("plan_upgraded", {
+ plan: currentPlan.name,
+ period,
+ revenue: currentPlan.price[period],
+ });
+ }
+ }
+ }, [searchParams, planId]);
const plan = planId
? PLANS.find((p) => p.name.toLowerCase() === planId.toLowerCase()) ??
@@ -45,7 +64,7 @@ function WelcomeModal({
setShowModal={setShowWelcomeModal}
onClose={() =>
queryParams({
- del: ["onboarded", "plan"],
+ del: ["onboarded", "upgraded", "plan", "period"],
})
}
>
@@ -88,14 +107,14 @@ function WelcomeModal({
plan ? "text-left" : "text-center",
)}
>
- Thanks for signing up &ndash; your account is ready to go! Now
- you have one central, organized place to build and manage all
- your short links.
+ {upgraded
+ ? `Thank you for upgrading to the ${plan?.name} plan! You now have access to more powerful features and higher limits.`
+ : "Thanks for signing up – your account is ready to go! Now you have one central, organized place to build and manage all your short links."}
</p>
{plan && (
<>
<h2 className="mb-2 mt-6 text-base font-medium text-gray-950">
- Explore the benefits of Dub {plan.name}
+ Explore the benefits of your {plan.name} plan
</h2>
<PlanFeatures plan={plan.name} />
</>
@@ -127,12 +146,6 @@ function WelcomeModal({
export function useWelcomeModal() {
const [showWelcomeModal, setShowWelcomeModal] = useState(false);
- const searchParams = useSearchParams();
- useEffect(
- () => setShowWelcomeModal(Boolean(searchParams?.get("onboarded"))),
- [searchParams],
- );
-
const WelcomeModalCallback = useCallback(() => {
return (
<WelcomeModal
diff --git a/apps/web/ui/workspaces/create-workspace-form.tsx b/apps/web/ui/workspaces/create-workspace-form.tsx
index 24f84a4547..3152e3a11d 100644
--- a/apps/web/ui/workspaces/create-workspace-form.tsx
+++ b/apps/web/ui/workspaces/create-workspace-form.tsx
@@ -4,7 +4,6 @@ import { AlertCircleFill } from "@/ui/shared/icons";
import { Button, InfoTooltip, useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
-import { trackEvent } from "fathom-client";
import { usePlausible } from "next-plausible";
import posthog from "posthog-js";
import { useForm } from "react-hook-form";
@@ -53,7 +52,6 @@ export function CreateWorkspaceForm({
if (res.ok) {
const { id: workspaceId } = await res.json();
- trackEvent("Created Workspace");
plausible("Created Workspace");
// track workspace creation event
posthog.capture("workspace_created", {
diff --git a/apps/web/ui/workspaces/upgrade-plan-button.tsx b/apps/web/ui/workspaces/upgrade-plan-button.tsx
index 2f5ad80b5b..9acc9930e6 100644
--- a/apps/web/ui/workspaces/upgrade-plan-button.tsx
+++ b/apps/web/ui/workspaces/upgrade-plan-button.tsx
@@ -4,7 +4,6 @@ import { getStripe } from "@/lib/stripe/client";
import useWorkspace from "@/lib/swr/use-workspace";
import { Button } from "@dub/ui";
import { APP_DOMAIN, capitalize, SELF_SERVE_PAID_PLANS } from "@dub/utils";
-import { trackEvent } from "fathom-client";
import { usePlausible } from "next-plausible";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import posthog from "posthog-js";
@@ -33,8 +32,6 @@ export function UpgradePlanButton({
const [clicked, setClicked] = useState(false);
- const queryString = searchParams.toString();
-
return (
<Button
text={text || `Upgrade to ${selectedPlan.name} ${capitalize(period)}`}
@@ -50,12 +47,11 @@ export function UpgradePlanButton({
body: JSON.stringify({
plan,
period,
- baseUrl: `${APP_DOMAIN}${pathname}${queryString.length > 0 ? `?${queryString}` : ""}`,
+ baseUrl: `${APP_DOMAIN}${pathname}`,
onboarding: searchParams.get("workspace"),
}),
})
.then(async (res) => {
- trackEvent("Opened Checkout");
plausible("Opened Checkout");
posthog.capture("checkout_opened", {
currentPlan: capitalize(plan),