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.

WIP- analytics settings onboarding

Ian MacCalluma4b13693a8bc
diff --git a/apps/web/app/api/docs/guides/[guide]/route.ts b/apps/web/app/api/docs/guides/[guide]/route.ts
new file mode 100644
index 0000000000..7441d49817
--- /dev/null
+++ b/apps/web/app/api/docs/guides/[guide]/route.ts
@@ -0,0 +1,12 @@
+import { withSession } from "@/lib/auth";
+import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdown";
+
+// GET /api/docs/guides/[guide] - get doc guide markdown
+export const GET = withSession(async ({ params }) => {
+ const { guide: rawGuide } = params;
+ const guide = rawGuide.replace(".md", "").toLowerCase();
+
+ const markdown = await getIntegrationGuideMarkdown(guide);
+
+ return new Response(markdown);
+});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/add-hostname-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/add-hostname-modal.tsx
new file mode 100644
index 0000000000..51023093db
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/add-hostname-modal.tsx
@@ -0,0 +1,168 @@
+"use client";
+
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { X } from "@/ui/shared/icons";
+import { Button, LoadingDots, Modal } from "@dub/ui";
+import { cn, validDomainRegex } from "@dub/utils";
+import { useCallback, useMemo, useState } from "react";
+import { toast } from "sonner";
+
+const AddHostnameForm = ({
+ onCreate,
+ onCancel,
+}: {
+ onCreate: () => void;
+ onCancel?: () => void;
+}) => {
+ const [hostname, setHostname] = useState("");
+ const [processing, setProcessing] = useState(false);
+ const { id, allowedHostnames, mutate, role } = useWorkspace();
+
+ const { error: permissionsError } = clientAccessCheck({
+ action: "workspaces.write",
+ role,
+ customPermissionDescription: "add hostnames",
+ });
+
+ const isValidHostname = (hostname: string) => {
+ return (
+ validDomainRegex.test(hostname) ||
+ hostname === "localhost" ||
+ hostname.startsWith("*.")
+ );
+ };
+
+ const addHostname = async () => {
+ if (allowedHostnames?.includes(hostname)) {
+ toast.error("Hostname already exists.");
+ return;
+ }
+
+ if (!isValidHostname(hostname)) {
+ toast.error("Enter a valid domain.");
+ return;
+ }
+
+ setProcessing(true);
+
+ const response = await fetch(`/api/workspaces/${id}`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ allowedHostnames: [...(allowedHostnames || []), hostname],
+ }),
+ });
+
+ if (response.ok) {
+ toast.success("Hostname added.");
+ onCreate();
+ } else {
+ const { error } = await response.json();
+ toast.error(error.message);
+ }
+
+ mutate();
+ setProcessing(false);
+ setHostname("");
+ };
+
+ return (
+ <form
+ className="bg-neutral-50"
+ onSubmit={(e) => {
+ e.preventDefault();
+ addHostname();
+ }}
+ >
+ <div className="relative flex-1 rounded-md px-6 py-5">
+ <input
+ type="text"
+ required
+ value={hostname}
+ onChange={(e) => setHostname(e.target.value)}
+ autoComplete="off"
+ placeholder="example.com or *.example.com"
+ className={cn(
+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ )}
+ />
+ </div>
+
+ <div className="flex items-center justify-between gap-2 border-t border-neutral-200 px-6 py-5">
+ <div>{processing && <LoadingDots />}</div>
+ <div className="items-centerend flex gap-2">
+ <Button
+ onClick={() => onCancel?.()}
+ variant="secondary"
+ text="Cancel"
+ className="h-8 w-fit px-3"
+ />
+ <Button
+ type="submit"
+ variant="primary"
+ text="Add hostname"
+ className="h-8 w-fit px-3"
+ onClick={addHostname}
+ disabled={!isValidHostname(hostname)}
+ loading={processing}
+ disabledTooltip={permissionsError || undefined}
+ />
+ </div>
+ </div>
+ </form>
+ );
+};
+
+interface AddHostnameModalProps {
+ showModal: boolean;
+ setShowModal: (showModal: boolean) => void;
+}
+
+const AddHostnameModal = ({
+ showModal,
+ setShowModal,
+}: AddHostnameModalProps) => {
+ const close = () => setShowModal(false);
+ return (
+ <Modal showModal={showModal} setShowModal={setShowModal}>
+ <div className="flex items-center justify-between border-b border-neutral-200 p-4">
+ <h3 className="text-lg font-medium">Add hostname</h3>
+ <button
+ type="button"
+ onClick={close}
+ className="group rounded-full p-2 text-neutral-500 transition-all duration-75 hover:bg-neutral-100 focus:outline-none active:bg-neutral-200"
+ >
+ <X className="h-5 w-5" />
+ </button>
+ </div>
+
+ <div className="bg-neutral-50">
+ <AddHostnameForm onCancel={close} onCreate={close} />
+ </div>
+ </Modal>
+ );
+};
+
+export function useAddHostnameModal() {
+ const [showAddHostnameModal, setShowAddHostnameModal] = useState(false);
+
+ const AddHostnameModalCallback = useCallback(() => {
+ return (
+ <AddHostnameModal
+ showModal={showAddHostnameModal}
+ setShowModal={setShowAddHostnameModal}
+ />
+ );
+ }, [showAddHostnameModal, setShowAddHostnameModal]);
+
+ return useMemo(
+ () => ({
+ setShowAddHostnameModal,
+ AddHostnameModal: AddHostnameModalCallback,
+ }),
+ [setShowAddHostnameModal, AddHostnameModalCallback],
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/allowed-hostnames-form.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/allowed-hostnames-form.tsx
deleted file mode 100644
index 25c1bc115e..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/allowed-hostnames-form.tsx
+++ /dev/null
@@ -1,212 +0,0 @@
-"use client";
-
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
-import useWorkspace from "@/lib/swr/use-workspace";
-import { useConfirmModal } from "@/ui/modals/confirm-modal";
-import { Button, CardList, CircleCheck, LoadingSpinner, Trash } from "@dub/ui";
-import { cn, validDomainRegex } from "@dub/utils";
-import Link from "next/link";
-import { useState } from "react";
-import { toast } from "sonner";
-
-export const AllowedHostnamesForm = () => {
- const { allowedHostnames, loading } = useWorkspace();
-
- return (
- <div className="grid gap-5 rounded-lg border border-neutral-200 p-5">
- <div className="flex flex-col gap-1">
- <h2 className="text-xl font-semibold tracking-tight text-black">
- Allowed Hostnames
- </h2>
- <p className="text-sm text-neutral-500">
- Specify a list of hostnames where client-side click tracking will be
- allowed on.{" "}
- <Link
- href="https://dub.co/docs/sdks/client-side/features/client-side-click-tracking"
- target="_blank"
- className="underline transition-colors hover:text-neutral-800"
- >
- Learn more.
- </Link>
- </p>
- </div>
- <div className="grid grid-cols-1 gap-3">
- <AddHostnameForm />
- <CardList variant="compact" loading={loading}>
- {allowedHostnames?.map((hostname) => (
- <AllowedHostnameCard key={hostname} hostname={hostname} />
- ))}
- </CardList>
- </div>
- </div>
- );
-};
-
-const AddHostnameForm = () => {
- const [hostname, setHostname] = useState("");
- const [processing, setProcessing] = useState(false);
- const { id, allowedHostnames, mutate, role } = useWorkspace();
-
- const { error: permissionsError } = clientAccessCheck({
- action: "workspaces.write",
- role,
- customPermissionDescription: "add hostnames",
- });
-
- const isValidHostname = (hostname: string) => {
- return (
- validDomainRegex.test(hostname) ||
- hostname === "localhost" ||
- hostname.startsWith("*.")
- );
- };
-
- const addHostname = async () => {
- if (allowedHostnames?.includes(hostname)) {
- toast.error("Hostname already exists.");
- return;
- }
-
- if (!isValidHostname(hostname)) {
- toast.error("Enter a valid domain.");
- return;
- }
-
- setProcessing(true);
-
- const response = await fetch(`/api/workspaces/${id}`, {
- method: "PATCH",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- allowedHostnames: [...(allowedHostnames || []), hostname],
- }),
- });
-
- if (response.ok) {
- toast.success("Hostname added.");
- } else {
- const { error } = await response.json();
- toast.error(error.message);
- }
-
- mutate();
- setProcessing(false);
- setHostname("");
- };
-
- return (
- <form
- className="flex items-end gap-2"
- onSubmit={(e) => {
- e.preventDefault();
- addHostname();
- }}
- >
- <div className="relative mt-2 flex-1 rounded-md shadow-sm">
- <input
- type="text"
- required
- value={hostname}
- onChange={(e) => setHostname(e.target.value)}
- autoComplete="off"
- placeholder="example.com or *.example.com"
- className={cn(
- "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- )}
- />
- </div>
-
- <Button
- text="Add Hostname"
- variant="primary"
- onClick={addHostname}
- disabled={!isValidHostname(hostname)}
- loading={processing}
- className="w-fit"
- disabledTooltip={permissionsError || undefined}
- />
- </form>
- );
-};
-
-const AllowedHostnameCard = ({ hostname }: { hostname: string }) => {
- const { id, allowedHostnames, mutate, role } = useWorkspace();
- const [processing, setProcessing] = useState(false);
-
- const { error: permissionsError } = clientAccessCheck({
- action: "workspaces.write",
- role,
- customPermissionDescription: "delete hostnames",
- });
-
- const handleDeleteHostname = async () => {
- setProcessing(true);
-
- const response = await fetch(`/api/workspaces/${id}`, {
- method: "PATCH",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- allowedHostnames: allowedHostnames?.filter((h) => h !== hostname),
- }),
- });
-
- if (response.ok) {
- toast.success("Hostname deleted.");
- } else {
- const { error } = await response.json();
- toast.error(error.message);
- }
-
- mutate();
- setProcessing(false);
- };
-
- const { setShowConfirmModal, confirmModal } = useConfirmModal({
- title: "Delete Hostname",
- description: `Are you sure you want to delete "${hostname}"? This action cannot be undone.`,
- confirmText: "Delete Hostname",
- onConfirm: handleDeleteHostname,
- });
-
- return (
- <CardList.Card
- key={hostname}
- innerClassName={cn(
- "flex items-center justify-between gap-5 sm:gap-8 md:gap-12 text-sm transition-opacity",
- processing && "opacity-50",
- )}
- hoverStateEnabled={false}
- >
- <div className="flex min-w-0 grow items-center gap-3">
- <CircleCheck className="size-4 text-green-500" />
- <span className="min-w-0 truncate whitespace-nowrap font-medium text-neutral-800">
- {hostname}
- </span>
- </div>
-
- <div className="flex items-center gap-5 sm:gap-8 md:gap-12">
- <Button
- variant="outline"
- className={cn(
- "h-8 px-1.5 outline-none transition-all duration-200",
- "border-transparent data-[state=open]:border-neutral-500 sm:group-hover/card:data-[state=closed]:border-neutral-200",
- )}
- icon={
- processing ? (
- <LoadingSpinner className="size-4 shrink-0" />
- ) : (
- <Trash className="size-4" />
- )
- }
- onClick={() => setShowConfirmModal(true)}
- disabledTooltip={permissionsError || undefined}
- />
- </div>
- {confirmModal}
- </CardList.Card>
- );
-};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/base-script-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/base-script-section.tsx
new file mode 100644
index 0000000000..7703a31c34
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/base-script-section.tsx
@@ -0,0 +1,47 @@
+"use client";
+
+import { LockSmall, Switch } from "@dub/ui";
+import { useId } from "react";
+import { HostnameSection } from "./hostname-section";
+
+const BaseScriptSection = () => {
+ const id = useId();
+
+ return (
+ <div className="flex flex-1 flex-col rounded-lg border border-neutral-200 bg-neutral-50">
+ <div className="flex items-center justify-between gap-4 p-5">
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="overflow-hidden">
+ <label
+ htmlFor={`${id}-switch`}
+ className="text-content-emphasis block text-sm font-semibold"
+ >
+ Base script
+ </label>
+ <p className="text-content-subtle text-sm font-medium">
+ Required for all Dub tracking
+ </p>
+ </div>
+ </div>
+
+ <Switch
+ disabledTooltip="Required for all Dub tracking"
+ disabled
+ checked={true}
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20 w-7 h-4"
+ thumbDimensions="size-3"
+ thumbTranslate="translate-x-3"
+ thumbIcon={
+ <div className="flex size-full items-center justify-center">
+ <LockSmall className="size-[8px] text-black" />
+ </div>
+ }
+ />
+ </div>
+
+ <HostnameSection className="border-t border-neutral-200" />
+ </div>
+ );
+};
+
+export default BaseScriptSection;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/complete-step-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/complete-step-button.tsx
new file mode 100644
index 0000000000..9d9075ff07
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/complete-step-button.tsx
@@ -0,0 +1,18 @@
+import { Button } from "@dub/ui";
+
+export const CompleteStepButton = ({
+ onClick,
+ loading,
+}: {
+ onClick: () => void;
+ loading?: boolean;
+}) => {
+ return (
+ <Button
+ text="Mark step as complete"
+ className=""
+ loading={loading}
+ onClick={onClick}
+ />
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/connection-instructions.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/connection-instructions.tsx
new file mode 100644
index 0000000000..e0b5181c40
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/connection-instructions.tsx
@@ -0,0 +1,69 @@
+"use client";
+
+import useGuide from "@/lib/swr/use-guide";
+import { GuideActionButton } from "@/ui/guides/guide-action-button";
+import { GuideSelector } from "@/ui/guides/guide-selector";
+import {
+ guides as allGuides,
+ IntegrationGuide,
+} from "@/ui/guides/integrations";
+import { GuidesMarkdown } from "@/ui/guides/markdown";
+import { useState } from "react";
+
+const ConnectionInstructions = ({}: {}) => {
+ const guides = allGuides.filter((guide) => guide.type === "client-sdk");
+ const [selectedGuide, setSelectedGuide] = useState<IntegrationGuide>(
+ guides[0],
+ );
+
+ const { loading, error, guideMarkdown } = useGuide(selectedGuide.key);
+
+ let button;
+ let content;
+
+ if (loading) {
+ content = (
+ <div className="space-y-4">
+ <div className="h-6 w-1/2 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-full animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-5/6 animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-2/3 animate-pulse rounded bg-neutral-100" />
+ </div>
+ );
+ button = (
+ <div className="h-8 w-24 animate-pulse rounded-md bg-neutral-200" />
+ );
+ } else if (guideMarkdown) {
+ content = <GuidesMarkdown>{guideMarkdown}</GuidesMarkdown>;
+ button = (
+ <GuideActionButton guide={selectedGuide} markdown={guideMarkdown} />
+ );
+ } else {
+ content = (
+ <div className="text-content-subtle flex size-full items-center justify-center text-sm">
+ Failed to load guide
+ </div>
+ );
+ }
+
+ return (
+ <div className="overflow-hidden rounded-xl border border-neutral-200 bg-neutral-50">
+ <div className="flex items-center justify-between p-3">
+ <GuideSelector
+ value={selectedGuide}
+ onChange={setSelectedGuide}
+ guides={guides}
+ className="-my-1 -ml-1"
+ />
+
+ {button}
+ </div>
+
+ <div className="max-w-full rounded-t-xl border-t border-neutral-200 bg-white p-5">
+ <div className="mx-auto max-w-2xl">{content}</div>
+ </div>
+ </div>
+ );
+};
+
+export default ConnectionInstructions;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-section.tsx
new file mode 100644
index 0000000000..ee261ba7f8
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-section.tsx
@@ -0,0 +1,63 @@
+"use client";
+
+import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
+import { Switch } from "@dub/ui";
+import { motion } from "motion/react";
+import Link from "next/link";
+import { useId } from "react";
+import { PublishableKeyForm } from "./publishable-key-form";
+
+const ConversionTrackingSection = () => {
+ const id = useId();
+
+ const [enabled, setEnabled, { loading }] = useWorkspaceStore<boolean>(
+ "analyticsSettingsConversionTrackingEnabled",
+ );
+
+ return (
+ <div className="flex flex-1 flex-col rounded-lg border border-neutral-200 bg-neutral-50">
+ <div className="gap-4m flex items-center justify-between p-5">
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="overflow-hidden">
+ <label
+ htmlFor={`${id}-switch`}
+ className="text-content-emphasis block text-sm font-semibold"
+ >
+ Conversion Tracking
+ </label>
+ <p className="text-content-subtle text-sm font-medium">
+ For tracking all conversions.{" "}
+ <Link className="underline" href={"/docs/conversions/quickstart"}>
+ Learn more
+ </Link>
+ </p>
+ </div>
+ </div>
+
+ <Switch
+ disabled={loading}
+ checked={enabled || false}
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20 w-7 h-4"
+ thumbDimensions="size-3"
+ thumbTranslate="translate-x-3"
+ fn={setEnabled}
+ />
+ </div>
+
+ <motion.div
+ animate={{
+ height: enabled ? "auto" : 0,
+ overflow: "hidden",
+ }}
+ transition={{
+ duration: 0.15,
+ }}
+ initial={false}
+ >
+ <PublishableKeyForm className="border-t border-neutral-200" />
+ </motion.div>
+ </div>
+ );
+};
+
+export default ConversionTrackingSection;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-toggle.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-toggle.tsx
deleted file mode 100644
index 32ee98742f..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/conversion-tracking-toggle.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-"use client";
-
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
-import useWorkspace from "@/lib/swr/use-workspace";
-import { Switch, TooltipContent } from "@dub/ui";
-import { ComponentProps, useEffect, useId, useState } from "react";
-import { toast } from "sonner";
-import { mutate } from "swr";
-
-export function ConversionTrackingToggle() {
- const id = useId();
-
- return (
- <div className="flex items-center justify-between gap-4 rounded-lg border border-neutral-200 bg-white p-5">
- <div className="flex min-w-0 items-center gap-4">
- <div className="overflow-hidden">
- <label
- htmlFor={`${id}-switch`}
- className="block text-pretty font-medium"
- >
- Workspace-level conversion tracking
- </label>
- <p className="mt-1 flex items-center gap-1 text-sm text-neutral-500">
- Enable conversion tracking for all future links in this workspace.
- This only affects links made with the link builder.
- </p>
- </div>
- </div>
- <ConversionTrackingToggleSwitch id={`${id}-switch`} />
- </div>
- );
-}
-
-export function ConversionTrackingToggleSwitch(
- props: ComponentProps<typeof Switch>,
-) {
- const {
- slug: workspaceSlug,
- plan,
- role,
- conversionEnabled: workspaceConversionEnabled,
- } = useWorkspace();
-
- const permissionsError = clientAccessCheck({
- action: "workspaces.write",
- role,
- }).error;
-
- const [conversionEnabled, setConversionEnabled] = useState(
- workspaceConversionEnabled,
- );
- const [isSubmitting, setIsSubmitting] = useState(false);
-
- useEffect(() => {
- setConversionEnabled(workspaceConversionEnabled);
- }, [workspaceConversionEnabled]);
-
- return (
- <Switch
- disabled={isSubmitting}
- disabledTooltip={
- plan === "free" || plan === "pro" ? (
- <TooltipContent
- title="You can only enable conversion tracking on Business plans and above."
- cta="Upgrade to Business"
- href={`/${workspaceSlug}/upgrade`}
- />
- ) : (
- permissionsError
- )
- }
- checked={conversionEnabled}
- fn={(checked) => {
- const oldConversionEnabled = conversionEnabled;
- setConversionEnabled(checked);
- setIsSubmitting(true);
- fetch(`/api/workspaces/${workspaceSlug}`, {
- method: "PATCH",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ conversionEnabled: checked }),
- })
- .then(async (res) => {
- if (res.ok) {
- toast.success(
- `Conversion tracking for new links ${checked ? "enabled" : "disabled"}.`,
- );
- await mutate(`/api/workspaces/${workspaceSlug}`);
- } else {
- const { error } = await res.json();
- toast.error(error.message);
- setConversionEnabled(oldConversionEnabled);
- }
- })
- .finally(() => setIsSubmitting(false));
- }}
- {...props}
- />
- );
-}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/guide.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/guide.tsx
new file mode 100644
index 0000000000..8be76ba814
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/guide.tsx
@@ -0,0 +1,18 @@
+"use client";
+
+import { GuidesMarkdown } from "@/ui/guides/markdown";
+import { use } from "react";
+
+export default function GuideMarkdown({
+ guideMarkdown,
+}: {
+ guideMarkdown: Promise<string | null>;
+}) {
+ const guide = use(guideMarkdown);
+
+ if (!guide) {
+ return null;
+ }
+
+ return <GuidesMarkdown>{guide}</GuidesMarkdown>;
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-menu.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-menu.tsx
new file mode 100644
index 0000000000..2a3a1ffa64
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-menu.tsx
@@ -0,0 +1,57 @@
+import { ThreeDots } from "@/ui/shared/icons";
+import { Button, LoadingSpinner, Popover } from "@dub/ui";
+import { Delete } from "lucide-react";
+import { useState } from "react";
+
+function HostnameMenu({
+ onDelete,
+ loading,
+}: {
+ onDelete: () => void;
+ loading: boolean;
+ permissionsError?: string;
+}) {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ return (
+ <Popover
+ content={
+ <div className="w-full sm:w-48">
+ <div className="grid gap-px p-2">
+ <Button
+ text="Delete"
+ variant="danger-outline"
+ onClick={() => {
+ setOpenPopover(false);
+ onDelete();
+ }}
+ icon={<Delete className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ </div>
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="plain"
+ color="secondary"
+ className="h-9 border-none p-2"
+ icon={
+ loading ? (
+ <LoadingSpinner className="size-4 shrink-0" />
+ ) : (
+ <ThreeDots className="h-5 w-5 shrink-0 rotate-90" />
+ )
+ }
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </Popover>
+ );
+}
+
+export default HostnameMenu;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-section.tsx
new file mode 100644
index 0000000000..97e2fa569a
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/hostname-section.tsx
@@ -0,0 +1,136 @@
+"use client";
+
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { Button, CardList, Globe, InfoTooltip } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useState } from "react";
+import { toast } from "sonner";
+import { useAddHostnameModal } from "./add-hostname-modal";
+import HostnameMenu from "./hostname-menu";
+
+export const HostnameSection = ({ className }: { className?: string }) => {
+ const { AddHostnameModal, setShowAddHostnameModal } = useAddHostnameModal();
+ const { allowedHostnames, loading } = useWorkspace();
+
+ let content;
+
+ if (allowedHostnames && allowedHostnames.length > 0) {
+ content = (
+ <div className="grid grid-cols-1 gap-2">
+ <CardList variant="compact" loading={loading}>
+ {allowedHostnames?.map((hostname) => (
+ <HostnameCard key={hostname} hostname={hostname} />
+ ))}
+ </CardList>
+ </div>
+ );
+ } else {
+ content = (
+ <div className="flex items-center justify-center rounded-xl border border-neutral-200 bg-neutral-100 p-3">
+ <p className="text-content-subtle text-sm font-medium">
+ No hostnames added
+ </p>
+ </div>
+ );
+ }
+
+ return (
+ <>
+ <div className={cn("flex flex-col gap-2 p-3", className)}>
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-0.5">
+ <h2 className="text-content-emphasis flex-1 text-sm font-semibold">
+ Allowed hostnames
+ </h2>
+ <InfoTooltip content="Add additional domains you own to track clicks to." />
+ </div>
+
+ <Button
+ text="Add hostname"
+ className="h-7 w-fit rounded-lg px-2.5 py-1 text-sm font-medium"
+ onClick={() => setShowAddHostnameModal(true)}
+ />
+ </div>
+
+ {content}
+ </div>
+
+ <AddHostnameModal />
+ </>
+ );
+};
+
+const HostnameCard = ({ hostname }: { hostname: string }) => {
+ const { id, allowedHostnames, mutate, role } = useWorkspace();
+ const [processing, setProcessing] = useState(false);
+
+ const { allowed: canWriteWorkspaces } = clientAccessCheck({
+ action: "workspaces.write",
+ role,
+ customPermissionDescription: "delete hostnames",
+ });
+
+ const handleDeleteHostname = async () => {
+ setProcessing(true);
+
+ const response = await fetch(`/api/workspaces/${id}`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ allowedHostnames: allowedHostnames?.filter((h) => h !== hostname),
+ }),
+ });
+
+ if (response.ok) {
+ toast.success("Hostname deleted.");
+ } else {
+ const { error } = await response.json();
+ toast.error(error.message);
+ }
+
+ mutate();
+ setProcessing(false);
+ };
+
+ const { setShowConfirmModal, confirmModal } = useConfirmModal({
+ title: "Delete Hostname",
+ description: `Are you sure you want to delete "${hostname}"? This action cannot be undone.`,
+ confirmText: "Delete Hostname",
+ onConfirm: handleDeleteHostname,
+ });
+
+ return (
+ <CardList.Card
+ key={hostname}
+ innerClassName={cn(
+ "flex items-center justify-between gap-5 sm:gap-8 md:gap-12 text-sm transition-opacity shadow-xs",
+ processing && "opacity-50",
+ )}
+ hoverStateEnabled={false}
+ >
+ <div className="flex min-w-0 grow items-center gap-3">
+ <div className="flex size-[28px] items-center justify-center rounded-md bg-neutral-100">
+ <Globe className="size-4 text-neutral-800" />
+ </div>
+
+ <span className="min-w-0 truncate whitespace-nowrap font-medium text-neutral-800">
+ {hostname}
+ </span>
+ </div>
+
+ <div className="flex items-center gap-5 sm:gap-8 md:gap-12">
+ {canWriteWorkspaces && (
+ <HostnameMenu
+ onDelete={() => setShowConfirmModal(true)}
+ loading={processing}
+ />
+ )}
+ </div>
+ {confirmModal}
+ </CardList.Card>
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/outbound-domain-tracking-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/outbound-domain-tracking-section.tsx
new file mode 100644
index 0000000000..22249a7a6f
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/outbound-domain-tracking-section.tsx
@@ -0,0 +1,51 @@
+"use client";
+
+import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
+import { Switch } from "@dub/ui";
+import Link from "next/link";
+import { useId } from "react";
+
+const OutboundDomainTrackingSection = () => {
+ const id = useId();
+
+ const [enabled, setEnabled, { loading }] = useWorkspaceStore<boolean>(
+ "analyticsSettingsOutboundDomainTrackingEnabled",
+ );
+
+ return (
+ <div className="flex flex-1 flex-col rounded-lg border border-neutral-200 bg-neutral-50">
+ <div className="gap-4m flex items-center justify-between p-5">
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="overflow-hidden">
+ <label
+ htmlFor={`${id}-switch`}
+ className="text-content-emphasis block text-sm font-semibold"
+ >
+ Outbound domain tracking
+ </label>
+ <p className="text-content-subtle text-sm font-medium">
+ Track outbound clicks to your other domains.{" "}
+ <Link
+ className="underline"
+ href="/docs/sdks/client-side/introduction#cross-domain-tracking"
+ >
+ Learn more
+ </Link>
+ </p>
+ </div>
+ </div>
+
+ <Switch
+ disabled={loading}
+ checked={enabled || false}
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20 w-7 h-4"
+ thumbDimensions="size-3"
+ thumbTranslate="translate-x-3"
+ fn={setEnabled}
+ />
+ </div>
+ </div>
+ );
+};
+
+export default OutboundDomainTrackingSection;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/page.tsx
index f008f6d9c0..95458b4633 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/page.tsx
@@ -1,13 +1,181 @@
-import { AllowedHostnamesForm } from "./allowed-hostnames-form";
-import { ConversionTrackingToggle } from "./conversion-tracking-toggle";
-import { PublishableKeyForm } from "./publishable-key-form";
+"use client";
+
+import Link from "next/link";
+
+import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
+import { useLocalStorage } from "@dub/ui";
+import BaseScriptSection from "./base-script-section";
+import { CompleteStepButton } from "./complete-step-button";
+import ConnectionInstructions from "./connection-instructions";
+import ConversionTrackingSection from "./conversion-tracking-section";
+import OutboundDomainTrackingSection from "./outbound-domain-tracking-section";
+import Step, { BaseStepProps } from "./step";
+import TrackLeadsGuidesSection from "./track-lead-guides-section";
+import TrackSalesGuidesSection from "./track-sales-guides-section";
+import VerifyInstall from "./verify-install";
+
+const ConnectStep = ({ expanded, toggleExpanded }: BaseStepProps) => {
+ return (
+ <Step
+ id="connect"
+ step={1}
+ title="Connect to Dub"
+ subtitle="Select scripts to enable page, conversion, and outbound tracking."
+ expanded={expanded}
+ toggleExpanded={toggleExpanded}
+ contentClassName="flex flex-col gap-8"
+ >
+ <div className="flex flex-col gap-3">
+ <BaseScriptSection />
+
+ <ConversionTrackingSection />
+
+ {/* TODO: Site visit tracking */}
+
+ <OutboundDomainTrackingSection />
+ </div>
+
+ <div className="flex flex-col gap-3">
+ <div>
+ <div className="font-semibold text-black">
+ Connection Instructions
+ </div>
+
+ <p className="text-content-subtle text-sm font-medium">
+ Select your integration method to show specific instructions
+ </p>
+ </div>
+
+ <ConnectionInstructions />
+ </div>
+
+ <VerifyInstall />
+ </Step>
+ );
+};
+
+const LeadEventsStep = ({
+ expanded,
+ toggleExpanded,
+ onComplete,
+}: BaseStepProps & { onComplete: () => void }) => {
+ const [complete, markComplete, { loading }] = useWorkspaceStore<boolean>(
+ "analyticsSettingsLeadTrackingSetupComplete",
+ );
+
+ return (
+ <Step
+ id="lead"
+ step={2}
+ title="Track lead events"
+ subtitle="For lead events from your server using our server side SDKs or the REST API"
+ expanded={expanded}
+ toggleExpanded={toggleExpanded}
+ complete={complete}
+ contentClassName="flex flex-col gap-5"
+ >
+ <TrackLeadsGuidesSection />
+
+ {!complete && (
+ <CompleteStepButton
+ onClick={() => {
+ markComplete(true);
+ onComplete();
+ }}
+ loading={loading}
+ />
+ )}
+ </Step>
+ );
+};
+
+const SaleEventsStep = ({
+ expanded,
+ toggleExpanded,
+ onComplete,
+}: BaseStepProps & { onComplete: () => void }) => {
+ const [complete, markComplete, { loading }] = useWorkspaceStore<boolean>(
+ "analyticsSettingsSaleTrackingSetupComplete",
+ );
+
+ return (
+ <Step
+ id="sale"
+ step={3}
+ title="Track sale events"
+ subtitle="Select scripts to enable page, conversion, and outbound tracking."
+ expanded={expanded}
+ toggleExpanded={toggleExpanded}
+ complete={complete}
+ contentClassName="flex flex-col gap-5"
+ >
+ <TrackSalesGuidesSection />
+
+ {!complete && (
+ <CompleteStepButton
+ onClick={() => {
+ markComplete(true);
+ onComplete();
+ }}
+ loading={loading}
+ />
+ )}
+ </Step>
+ );
+};
export default function WorkspaceAnalytics() {
+ const [expandedStep, setExpandedStep] = useLocalStorage<Step | null>(
+ "analytics-settings",
+ "connect",
+ );
+
+ const toggleStep = (step: Step) => {
+ if (expandedStep === step) {
+ setExpandedStep(null);
+ } else {
+ setExpandedStep(step);
+ }
+ };
+
+ const closeStep = (step: Step) => {
+ if (expandedStep === step) {
+ setExpandedStep(null);
+ }
+ };
+
return (
- <div className="flex h-full flex-col gap-10">
- <AllowedHostnamesForm />
- <PublishableKeyForm />
- <ConversionTrackingToggle />
+ <div className="flex h-full flex-col gap-8 overflow-hidden">
+ <div className="flex flex-wrap justify-between gap-6">
+ <h1 className="text-2xl font-semibold tracking-tight text-black">
+ Analytics
+ </h1>
+ <div className="flex w-full items-center gap-3 sm:w-auto">
+ <Link
+ href={"/docs"}
+ className="text-content-emphasis border-border-subtle rounded-lg border px-3 py-1.5 text-sm font-medium"
+ >
+ Docs ↗
+ </Link>
+ </div>
+ </div>
+
+ <div className="flex flex-1 flex-col gap-8 overflow-hidden">
+ <ConnectStep
+ expanded={expandedStep === "connect"}
+ toggleExpanded={() => toggleStep("connect")}
+ />
+ <LeadEventsStep
+ expanded={expandedStep === "lead"}
+ toggleExpanded={() => toggleStep("lead")}
+ onComplete={() => closeStep("lead")}
+ />
+ <SaleEventsStep
+ expanded={expandedStep === "sale"}
+ toggleExpanded={() => toggleStep("sale")}
+ onComplete={() => closeStep("sale")}
+ />
+ </div>
</div>
);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-form.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-form.tsx
index e960d4fd05..9bf0d5593c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-form.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-form.tsx
@@ -3,13 +3,13 @@
import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
-import { Button, CopyButton } from "@dub/ui";
-import { nanoid } from "@dub/utils";
-import Link from "next/link";
+import { Button, CopyButton, InfoTooltip, Key } from "@dub/ui";
+import { cn, nanoid } from "@dub/utils";
import { useState } from "react";
import { toast } from "sonner";
+import PublishableKeyMenu from "./publishable-key-menu";
-export const PublishableKeyForm = () => {
+export const PublishableKeyForm = ({ className }: { className?: string }) => {
const { id, publishableKey, mutate, role } = useWorkspace();
const [processing, setProcessing] = useState(false);
@@ -89,27 +89,19 @@ export const PublishableKeyForm = () => {
});
return (
- <div className="rounded-lg border border-neutral-200 p-5">
- <div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
- <div className="flex flex-col gap-1">
- <h2 className="text-xl font-semibold tracking-tight text-black">
- Publishable Key
+ <div className={cn("flex flex-col gap-2 p-3", className)}>
+ <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
+ <div className="flex items-center gap-0.5">
+ <h2 className="text-content-emphasis flex-1 text-sm font-semibold">
+ Publishable key
</h2>
- <p className="text-sm text-neutral-500">
- Use this key for client-side conversion tracking.{" "}
- <Link
- href="https://dub.co/docs/sdks/client-side/features/conversion-tracking"
- target="_blank"
- className="underline transition-colors hover:text-neutral-800"
- >
- Learn more.
- </Link>
- </p>
+ <InfoTooltip content="Required for conversion tracking." />
</div>
+
{!publishableKey && (
<Button
- text="Generate Key"
- className="h-8 w-fit px-3 sm:shrink-0"
+ text="Generate"
+ className="w-fit rounded-lg px-2.5 py-1 text-sm font-medium h-7"
onClick={() => setShowGenerateModal(true)}
loading={processing}
disabledTooltip={permissionsError || undefined}
@@ -118,41 +110,38 @@ export const PublishableKeyForm = () => {
</div>
{publishableKey ? (
- <div className="mt-5 space-y-3">
- <div className="flex flex-col gap-3 rounded-md border border-neutral-200 p-3 sm:flex-row sm:items-center sm:justify-between sm:gap-2">
- <div className="flex min-w-0 items-center gap-2">
+ <div className="flex flex-col gap-3 rounded-xl border border-neutral-200 bg-white p-3 sm:flex-row sm:items-center sm:justify-between sm:gap-2">
+ <div className="flex min-w-0 items-center gap-2">
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="flex size-[28px] items-center justify-center rounded-md bg-neutral-100">
+ <Key className="size-4 text-neutral-800" />
+ </div>
<code className="min-w-0 flex-1 truncate font-mono text-sm text-neutral-800">
{publishableKey}
</code>
- <CopyButton value={publishableKey} className="shrink-0" />
- </div>
- <div className="flex w-fit items-center gap-2 sm:shrink-0">
- <Button
- text="Regenerate"
- variant="secondary"
- onClick={() => setShowGenerateModal(true)}
- loading={processing}
- disabledTooltip={permissionsError || undefined}
- className="h-7 w-fit flex-1 px-2 text-xs sm:flex-none"
- />
- <Button
- text="Revoke"
- variant="danger"
- onClick={() => setShowRevokeModal(true)}
- loading={processing}
- disabledTooltip={permissionsError || undefined}
- className="h-7 w-fit flex-1 px-2 text-xs sm:flex-none"
- />
</div>
+ <CopyButton value={publishableKey} className="shrink-0" />
+ </div>
+ <div className="flex w-fit items-center gap-2 sm:shrink-0">
+ <Button
+ text="Regenerate"
+ variant="secondary"
+ onClick={() => setShowGenerateModal(true)}
+ loading={processing}
+ disabledTooltip={permissionsError || undefined}
+ className="h-7 w-fit flex-1 px-2 text-xs sm:flex-none"
+ />
+ <PublishableKeyMenu
+ onRevoke={() => setShowRevokeModal(true)}
+ loading={processing}
+ />
</div>
</div>
) : (
- <div className="mt-5">
- <div className="flex items-center justify-center rounded-md border border-dashed border-neutral-300 p-8">
- <p className="text-sm text-neutral-500">
- No publishable key configured
- </p>
- </div>
+ <div className="flex items-center justify-center rounded-xl border border-neutral-200 bg-neutral-100 p-3">
+ <p className="text-content-subtle text-sm font-medium">
+ No publishable key created
+ </p>
</div>
)}
{generateModal}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-menu.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-menu.tsx
new file mode 100644
index 0000000000..d4937efcee
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/publishable-key-menu.tsx
@@ -0,0 +1,52 @@
+import { ThreeDots } from "@/ui/shared/icons";
+import { Button, Popover } from "@dub/ui";
+import { Delete } from "lucide-react";
+import { useState } from "react";
+
+function PublishableKeyMenu({
+ onRevoke,
+ loading,
+}: {
+ onRevoke: () => void;
+ loading: boolean;
+ permissionsError?: string;
+}) {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ return (
+ <Popover
+ content={
+ <div className="w-full sm:w-48">
+ <div className="grid gap-px p-2">
+ <Button
+ text="Revoke"
+ variant="danger-outline"
+ onClick={() => {
+ setOpenPopover(false);
+ onRevoke();
+ }}
+ icon={<Delete className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ loading={loading}
+ />
+ </div>
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="plain"
+ color="secondary"
+ className="h-9 border-none p-2"
+ icon={<ThreeDots className="h-5 w-5 shrink-0 rotate-90" />}
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </Popover>
+ );
+}
+
+export default PublishableKeyMenu;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/step.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/step.tsx
new file mode 100644
index 0000000000..5800943c96
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/step.tsx
@@ -0,0 +1,110 @@
+"use client";
+
+import { PropsWithChildren } from "react";
+
+import { Button, Check2 } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { ChevronDown } from "lucide-react";
+import { AnimatePresence, motion } from "motion/react";
+import { ReactNode } from "react";
+
+type Step = "connect" | "lead" | "sale";
+
+export type BaseStepProps = {
+ expanded?: boolean;
+ toggleExpanded: () => void;
+};
+
+export type StepProps = BaseStepProps & {
+ id: Step;
+ step: number;
+ title: string;
+ subtitle?: string;
+ complete?: boolean;
+ children?: ReactNode;
+ contentClassName?: string;
+};
+
+const Step = ({
+ step,
+ title,
+ subtitle,
+ complete,
+ expanded,
+ toggleExpanded,
+ children,
+ contentClassName,
+}: PropsWithChildren<StepProps>) => {
+ return (
+ <div className="flex items-start gap-[22px] rounded-xl border border-neutral-200 bg-white p-5">
+ <StepNumber number={step} complete={complete} />
+
+ <div className="flex flex-1 flex-col gap-5">
+ <div className="flex items-center justify-between gap-2">
+ <div>
+ <div className="text-content-emphasis text-base font-semibold">
+ {title}
+ </div>
+ {subtitle && (
+ <div className="test-sm text-content-subtle font-medium">
+ {subtitle}
+ </div>
+ )}
+ </div>
+
+ <Button
+ variant="plain"
+ className="hover:bg-bg-subtle size-8 w-fit rounded-full border-none px-2"
+ data-state={expanded ? "open" : "closed"}
+ text={
+ <ChevronDown className="text-content-emphasis size-4 transition-transform duration-75 data-[state=open]:rotate-180" />
+ }
+ onClick={() => toggleExpanded()}
+ />
+ </div>
+
+ <AnimatePresence initial={false}>
+ {expanded && (
+ <motion.div
+ className={cn(contentClassName, "flex-1 overflow-y-scroll")}
+ key="step-content"
+ initial={{ opacity: 0, height: 0 }}
+ animate={{ opacity: 1, height: "auto" }}
+ exit={{ opacity: 0, height: 0 }}
+ transition={{ duration: 0.2, ease: "easeInOut" }}
+ >
+ {children}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </div>
+ </div>
+ );
+};
+
+const StepNumber = ({
+ number,
+ complete,
+}: {
+ number: number;
+ complete?: boolean;
+}) => {
+ return (
+ <div
+ className={cn(
+ "flex size-[42px] shrink-0 items-center justify-center rounded-full",
+ complete ? "bg-green-400" : "bg-neutral-100",
+ )}
+ >
+ {complete ? (
+ <Check2 className="size-4 text-green-800" />
+ ) : (
+ <span className="text-content-default text-base font-semibold">
+ {number}
+ </span>
+ )}
+ </div>
+ );
+};
+
+export default Step;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-lead-guides-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-lead-guides-section.tsx
new file mode 100644
index 0000000000..c6d2f43ae3
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-lead-guides-section.tsx
@@ -0,0 +1,69 @@
+"use client";
+
+import useGuide from "@/lib/swr/use-guide";
+import { GuideActionButton } from "@/ui/guides/guide-action-button";
+import { GuideSelector } from "@/ui/guides/guide-selector";
+import {
+ guides as allGuides,
+ IntegrationGuide,
+} from "@/ui/guides/integrations";
+import { GuidesMarkdown } from "@/ui/guides/markdown";
+import { useState } from "react";
+
+const TrackLeadsGuidesSection = ({}: {}) => {
+ const guides = allGuides.filter((guide) => guide.type === "track-lead");
+ const [selectedGuide, setSelectedGuide] = useState<IntegrationGuide>(
+ guides[0],
+ );
+
+ const { loading, error, guideMarkdown } = useGuide(selectedGuide.key);
+
+ let button;
+ let content;
+
+ if (loading) {
+ content = (
+ <div className="space-y-4">
+ <div className="h-6 w-1/2 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-full animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-5/6 animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-2/3 animate-pulse rounded bg-neutral-100" />
+ </div>
+ );
+ button = (
+ <div className="h-8 w-24 animate-pulse rounded-md bg-neutral-200" />
+ );
+ } else if (guideMarkdown) {
+ content = <GuidesMarkdown>{guideMarkdown}</GuidesMarkdown>;
+ button = (
+ <GuideActionButton guide={selectedGuide} markdown={guideMarkdown} />
+ );
+ } else {
+ content = (
+ <div className="text-content-subtle flex size-full items-center justify-center text-sm">
+ Failed to load guide
+ </div>
+ );
+ }
+
+ return (
+ <div className="overflow-hidden rounded-xl border border-neutral-200 bg-neutral-50">
+ <div className="flex items-center justify-between p-3">
+ <GuideSelector
+ value={selectedGuide}
+ onChange={setSelectedGuide}
+ guides={guides}
+ className="-my-1 -ml-1"
+ />
+
+ {button}
+ </div>
+
+ <div className="max-w-full rounded-t-xl border-t border-neutral-200 bg-white p-5">
+ <div className="mx-auto max-w-2xl">{content}</div>
+ </div>
+ </div>
+ );
+};
+
+export default TrackLeadsGuidesSection;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-sales-guides-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-sales-guides-section.tsx
new file mode 100644
index 0000000000..1154e5b76d
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/track-sales-guides-section.tsx
@@ -0,0 +1,69 @@
+"use client";
+
+import useGuide from "@/lib/swr/use-guide";
+import { GuideActionButton } from "@/ui/guides/guide-action-button";
+import { GuideSelector } from "@/ui/guides/guide-selector";
+import {
+ guides as allGuides,
+ IntegrationGuide,
+} from "@/ui/guides/integrations";
+import { GuidesMarkdown } from "@/ui/guides/markdown";
+import { useState } from "react";
+
+const TrackSalesGuidesSection = ({}: {}) => {
+ const guides = allGuides.filter((guide) => guide.type === "track-sale");
+ const [selectedGuide, setSelectedGuide] = useState<IntegrationGuide>(
+ guides[0],
+ );
+
+ const { loading, error, guideMarkdown } = useGuide(selectedGuide.key);
+
+ let button;
+ let content;
+
+ if (loading) {
+ content = (
+ <div className="space-y-4">
+ <div className="h-6 w-1/2 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-full animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-5/6 animate-pulse rounded bg-neutral-100" />
+ <div className="h-4 w-2/3 animate-pulse rounded bg-neutral-100" />
+ </div>
+ );
+ button = (
+ <div className="h-8 w-24 animate-pulse rounded-md bg-neutral-200" />
+ );
+ } else if (guideMarkdown) {
+ content = <GuidesMarkdown>{guideMarkdown}</GuidesMarkdown>;
+ button = (
+ <GuideActionButton guide={selectedGuide} markdown={guideMarkdown} />
+ );
+ } else {
+ content = (
+ <div className="text-content-subtle flex size-full items-center justify-center text-sm">
+ Failed to load guide
+ </div>
+ );
+ }
+
+ return (
+ <div className="overflow-hidden rounded-xl border border-neutral-200 bg-neutral-50">
+ <div className="flex items-center justify-between p-3">
+ <GuideSelector
+ value={selectedGuide}
+ onChange={setSelectedGuide}
+ guides={guides}
+ className="-my-1 -ml-1"
+ />
+
+ {button}
+ </div>
+
+ <div className="max-w-full rounded-t-xl border-t border-neutral-200 bg-white p-5">
+ <div className="mx-auto max-w-2xl">{content}</div>
+ </div>
+ </div>
+ );
+};
+
+export default TrackSalesGuidesSection;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/verify-install.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/verify-install.tsx
new file mode 100644
index 0000000000..e29791af5a
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/analytics/verify-install.tsx
@@ -0,0 +1,150 @@
+import { verifyWorkspaceSetup } from "@/lib/actions/verify-workspace-setup";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Button, Plug2 } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { motion } from "motion/react";
+import { useAction } from "next-safe-action/hooks";
+import Link from "next/link";
+import { useMemo } from "react";
+import { toast } from "sonner";
+
+type VerifyStatus = "pending" | "success" | "error";
+
+const VerifyInstallIcon = ({ status }: { status: VerifyStatus }) => {
+ return (
+ <div
+ className={cn(
+ "flex size-[42px] items-center justify-center rounded-full",
+ status === "pending" && "border border-blue-200 bg-white",
+ status === "error" && "",
+ status === "success" && "",
+ )}
+ >
+ <Plug2 className="text-content-default size-[18px]" />
+ </div>
+ );
+};
+
+type VerificationResponse = {
+ verifiedAt: Date;
+ verifiedBy: { name: string; avatarUrl?: string };
+};
+
+const VerifyInstall = () => {
+ const { id: workspaceId } = useWorkspace();
+
+ // const [verified, setVerified] = useState(false);
+
+ const error: any | null = null;
+ const response: VerificationResponse | null = null;
+ // const response: VerificationResponse | null = {
+ // verifiedAt: new Date(),
+ // verifiedBy: { name: "Ian" },
+ // };
+
+ const { executeAsync, isPending } = useAction(verifyWorkspaceSetup, {
+ async onSuccess(response) {
+ toast.success("Account created! Redirecting to dashboard...");
+
+ // if (response?.ok) {
+ // } else {
+ // toast.error(
+ // "Failed to sign in with credentials. Please try again or contact support.",
+ // );
+ // }
+ },
+ onError({ error }) {
+ toast.error(error.serverError);
+ },
+ });
+
+ const status: VerifyStatus = useMemo(() => {
+ if (error) return "error";
+ if (response) return "success";
+ return "pending";
+ }, [response, error]);
+
+ const title = useMemo(() => {
+ if (error) return "Unable to connect";
+ if (response) return "Successfully connected!";
+ return "Verify your install";
+ }, [response, error]);
+
+ const subtitle = useMemo(() => {
+ if (error)
+ return (
+ <>
+ Try again. For more help, see our{" "}
+ <Link href={"/docs"} className="underline">
+ docs
+ </Link>{" "}
+ or{" "}
+ <Link href={"/contact"} className="underline">
+ contact support
+ </Link>
+ .
+ </>
+ );
+ if (response) return "You’re connected and ready to track conversions";
+ return "Test your connection to Dub";
+ }, [response, error]);
+
+ return (
+ <div
+ className={cn(
+ "flex flex-col gap-3 rounded-xl border px-8 py-6",
+ status === "pending" &&
+ "border-blue-200 bg-gradient-to-b from-blue-50 to-white",
+ status === "error" && "",
+ status === "success" && "",
+ )}
+ >
+ <form
+ onSubmit={(e) => {
+ if (!workspaceId) {
+ return;
+ }
+
+ e.preventDefault();
+ executeAsync({ workspaceId });
+ }}
+ >
+ <div>
+ <div className="flex flex-col items-center">
+ <VerifyInstallIcon status={status} />
+
+ <div className="text-content-emphasis font-semibold">{title}</div>
+
+ <p className="text-content-emphasis text-sm font-medium">
+ {subtitle}
+ </p>
+ </div>
+
+ <Button
+ className="mt-8"
+ text={isPending ? "Verifying..." : "Verify"}
+ type="submit"
+ loading={isPending}
+ disabled={isPending}
+ variant={status === "pending" ? "success" : "primary"}
+ />
+
+ <motion.div
+ animate={{
+ height: !!response ? "auto" : 0,
+ overflow: "hidden",
+ }}
+ transition={{
+ duration: 0.15,
+ }}
+ initial={false}
+ >
+ Last verified by
+ </motion.div>
+ </div>
+ </form>
+ </div>
+ );
+};
+
+export default VerifyInstall;
diff --git a/apps/web/lib/actions/verify-workspace-setup.ts b/apps/web/lib/actions/verify-workspace-setup.ts
new file mode 100644
index 0000000000..dc0c8dfd0b
--- /dev/null
+++ b/apps/web/lib/actions/verify-workspace-setup.ts
@@ -0,0 +1,199 @@
+"use server";
+
+import { prisma } from "@dub/prisma";
+import { getHtml } from "app/api/links/metatags/utils";
+import { parse } from "node-html-parser";
+import z from "../zod";
+import { authActionClient } from "./safe-action";
+
+// Improved getScriptTags: more robust extraction of script src and inline content
+const getScriptTags = (html: string) => {
+ const ast = parse(html, {
+ blockTextElements: {
+ script: true,
+ },
+ });
+
+ // node-html-parser v6: .querySelectorAll returns Node[], which may be HTMLElement or TextNode
+ // We want to extract both src and inline content
+ return ast.querySelectorAll("script").map((node) => {
+ // node.getAttribute returns undefined if not present
+ const src = node.getAttribute("src") || null;
+ // node.innerHTML gives the inline script content
+ // node.text gives the text content (should be same for script)
+ const content = node.innerHTML?.trim() || null;
+ return { src, content };
+ });
+};
+
+const expectedScriptForWorkspace = (workspace: any) => {
+ const store = workspace.store as Record<string, any>;
+
+ const {
+ analyticsSettingsConversionTrackingEnabled: conversionTrackingEnabled,
+ analyticsSettingsSiteVisitTrackingEnabled: siteVisitEnabled,
+ analyticsSettingsOutboundDomainTrackingEnabled: outboundDomainsEnabled,
+ } = store;
+
+ const components = [
+ "script",
+ siteVisitEnabled ? "site-visit" : null,
+ outboundDomainsEnabled ? "outbound-domains" : null,
+ conversionTrackingEnabled ? "conversion-tracking" : null,
+ ].filter(Boolean);
+
+ return `${components.join(".")}.js`;
+};
+
+type DubScript = {};
+
+const getDubScript = (html: string): DubScript | null => {
+ const scripts = getScriptTags(html);
+
+ console.log("SCRIPTS:");
+ console.log(scripts.map((s) => s.src).filter(Boolean));
+ return null;
+};
+
+const schema = z.object({
+ workspaceId: z.string(),
+});
+
+// Attempt to verify the workspace setup
+export const verifyWorkspaceSetup = authActionClient
+ .schema(schema)
+ .action(async ({ ctx }) => {
+ const { workspace } = ctx;
+
+ const domains = await prisma.domain.findMany({
+ where: { projectId: workspace.id },
+ select: { slug: true },
+ });
+
+ const domain = domains[0];
+
+ if (!domain) {
+ throw new Error(`Please setup a domain`);
+ }
+
+ // const siteUrl = domain.slug;
+ const siteUrl = "https://dub.co/home";
+
+ // Verify the hostname is allowed for the domain
+ const hostnames = (workspace.allowedHostnames as string[]) || [];
+
+ if (!hostnames.length) {
+ throw new Error(`Add a hostname for your domain`);
+ }
+
+ const expectedScript = expectedScriptForWorkspace(workspace);
+
+ // Scrape the domain for scripts and find the analytics script tag
+ // const firecrawl = new FirecrawlApp({
+ // apiKey: process.env.FIRECRAWL_API_KEY,
+ // });
+
+ // const scrapeResult = await firecrawl.scrapeUrl(siteUrl, {
+ // formats: ["html"],
+ // onlyMainContent: false,
+ // parsePDF: false,
+ // maxAge: 14400000,
+ // });
+
+ // if (!scrapeResult.success) {
+ // throw new Error("Failed to verify site");
+ // }
+
+ const html = await getHtml(siteUrl);
+
+ if (!html) {
+ throw new Error("Failed to verify site");
+ }
+
+ const dubScript = getDubScript(html);
+
+ if (!dubScript) {
+ throw new Error("Dub script not found");
+ }
+
+ // console.log(`result: `);
+ // // console.log(scrapeResult.html);
+
+ // // Try to find the analytics script tag in links
+ // let analyticsScriptSrc: string | null = null;
+
+ // // If not found in links, try to find in HTML using regex
+ // if (!analyticsScriptSrc && scrapeResult.html) {
+ // const scriptRegex =
+ // /<script[^>]+src=["'](https:\/\/www\.dubcdn\.com\/analytics[^"']*)["'][^>]*><\/script>/gi;
+ // const matches = [...scrapeResult.html.matchAll(scriptRegex)];
+ // console.log("MATCHES");
+ // console.log(matches);
+ // if (matches.length > 0) {
+ // analyticsScriptSrc = matches[0][1];
+ // }
+ // }
+
+ // console.log(`SCRIPT: ${analyticsScriptSrc}`);
+
+ // Find the script tag for https://www.dubcdn.com/analytics
+ // Try to find in links first, then fallback to html if needed
+ // let analyticsScriptFound = false;
+ // let scriptTag: string | null = null;
+
+ // const script = scrapeResult.links?.find(link => {
+ // return link.type === "script" &&
+ // typeof link.src === "string" &&
+ // link.src.startsWith("https://www.dubcdn.com/analytics")
+
+ // });
+
+ // // Check in links
+ // if (scrapeResult.links && Array.isArray(scrapeResult.links)) {
+ // for (const link of scrapeResult.links) {
+ // if (
+ // ) {
+ // analyticsScriptFound = true;
+ // scriptTag = link.src;
+ // break;
+ // }
+ // }
+ // }
+
+ // If not found in links, try to parse from HTML
+ // if (!analyticsScriptFound && scrapeResult.html) {
+ // // Use a simple regex to find the script tag
+ // const scriptRegex =
+ // /<script[^>]+src=["'](https:\/\/www\.dubcdn\.com\/analytics[^"']*)["'][^>]*><\/script>/gi;
+ // const matches = [...scrapeResult.html.matchAll(scriptRegex)];
+ // if (matches.length > 0) {
+ // analyticsScriptFound = true;
+ // scriptTag = matches[0][1];
+ // }
+ // }
+
+ // if (!analyticsScriptFound) {
+ // throw new Error(
+ // "Could not find the analytics script tag for https://www.dubcdn.com/analytics on your site.",
+ // );
+ // }
+
+ // Optionally, you could check if the scriptTag matches the expectedScript
+ // For now, just return the found script src
+
+ // Handle data domains
+ // You definid
+
+ // Check refer
+ // usePropgram -- domain -- if they have a program domain, we construct the script with the refer prop matching the domain
+ // if not, they are running a referral program they need to know
+
+ // Check site
+
+ // Check outbound matches
+
+ return {
+ verifiedAt: new Date().toISOString(),
+ // analyticsScriptSrc: scriptTag,
+ };
+ });
diff --git a/apps/web/lib/api/tokens/permissions.ts b/apps/web/lib/api/tokens/permissions.ts
index e7adaa2091..3fb4e4d976 100644
--- a/apps/web/lib/api/tokens/permissions.ts
+++ b/apps/web/lib/api/tokens/permissions.ts
@@ -49,14 +49,17 @@ export const clientAccessCheck = ({
}) => {
const permission = ROLE_PERMISSIONS.find((p) => p.action === action)!;
const allowedRoles = permission.roles;
+ const allowed = allowedRoles.includes(role);
- if (allowedRoles.includes(role)) {
+ if (allowed) {
return {
+ allowed,
error: false,
};
}
return {
+ allowed,
error: `Only workspace ${combineWords(allowedRoles.map((r) => `${r}s`))} can ${customPermissionDescription || permission.description}.`,
};
};
diff --git a/apps/web/lib/swr/use-guide.ts b/apps/web/lib/swr/use-guide.ts
new file mode 100644
index 0000000000..150ed45112
--- /dev/null
+++ b/apps/web/lib/swr/use-guide.ts
@@ -0,0 +1,19 @@
+import { textFetcher } from "@dub/utils";
+import useSWR, { SWRConfiguration } from "swr";
+
+export default function useGuide(guideKey: string, swrOpts?: SWRConfiguration) {
+ const { data: guideMarkdown, error } = useSWR(
+ `/api/docs/guides/${guideKey}.md`,
+ textFetcher,
+ {
+ keepPreviousData: true,
+ ...swrOpts,
+ },
+ );
+
+ return {
+ guideMarkdown,
+ error,
+ loading: !guideMarkdown && !error,
+ };
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 9d5a9a7f5e..4f62b2a32d 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -122,6 +122,7 @@ import {
workflowConditionSchema,
} from "./zod/schemas/workflows";
import { workspacePreferencesSchema } from "./zod/schemas/workspace-preferences";
+import { workspaceStoreKeys } from "./zod/schemas/workspaces";
export type LinkProps = Link;
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 5ec92a199f..fd11d09b27 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -184,4 +184,10 @@ export const workspaceStoreKeys = z.enum([
"conversionsOnboarding", // boolean
"dubPartnersPopupDismissed", // boolean
"dotLinkOfferDismissed", // string
+ "analyticsSettingsConversionTrackingEnabled", // boolean
+ "analyticsSettingsSiteVisitTrackingEnabled", // boolean
+ "analyticsSettingsOutboundDomainTrackingEnabled", // boolean
+ "analyticsSettingsConnectionSeupComplete", // boolean
+ "analyticsSettingsLeadTrackingSetupComplete", // boolean
+ "analyticsSettingsSaleTrackingSetupComplete", // boolean
]);
diff --git a/apps/web/ui/guides/guide-action-button.tsx b/apps/web/ui/guides/guide-action-button.tsx
new file mode 100644
index 0000000000..8b6ea71b8b
--- /dev/null
+++ b/apps/web/ui/guides/guide-action-button.tsx
@@ -0,0 +1,132 @@
+import {
+ Anthropic,
+ BookOpen,
+ Button,
+ Check,
+ OpenAI,
+ Popover,
+ useCopyToClipboard,
+} from "@dub/ui";
+import { cn } from "@dub/utils";
+import { ArrowUpRight, ChevronDown, Copy } from "lucide-react";
+import Link from "next/link";
+import { useState } from "react";
+import { toast } from "sonner";
+import { IntegrationGuide } from "./integrations";
+
+export const GuideActionButton = ({
+ guide,
+ markdown,
+}: {
+ guide: IntegrationGuide;
+ markdown: string;
+}) => {
+ const [openDropdown, setOpenDropdown] = useState(false);
+
+ const [copied, copyToClipboard] = useCopyToClipboard();
+
+ const prompt = `Read from ${guide.url} so I can ask questions about it.`;
+
+ return (
+ <div className="border-border-subtle flex h-8 items-center overflow-hidden rounded-lg border">
+ <Link href={guide.url} target="_blank" rel="noopener noreferrer">
+ <Button
+ text="Read full guide"
+ variant="secondary"
+ className="rounded-none border-0 px-3"
+ icon={<BookOpen className="size-3.5" />}
+ />
+ </Link>
+
+ <div className="h-8 w-px bg-neutral-200" />
+
+ <Popover
+ content={
+ <div className="flex w-full flex-col space-y-px rounded-lg bg-white p-1 sm:min-w-64">
+ <button
+ className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
+ onClick={() =>
+ copyToClipboard(markdown, {
+ onSuccess: () => {
+ toast.success("Content copied as markdown");
+ },
+ })
+ }
+ >
+ <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
+ {copied ? (
+ <Check className="size-4 text-neutral-600" />
+ ) : (
+ <Copy className="size-4 text-neutral-600" />
+ )}
+ </div>
+ <div className="flex flex-col items-start">
+ <span className="font-medium">Copy content</span>
+ <span className="text-xs text-neutral-500">
+ Copy page as Markdown for LLMs
+ </span>
+ </div>
+ </button>
+
+ <button
+ className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
+ onClick={() => {
+ const chatgptUrl = `https://chatgpt.com?hints=search&prompt=${encodeURIComponent(prompt)}`;
+ console.log("chatgptUrl", chatgptUrl);
+ window.open(chatgptUrl, "_blank", "noopener,noreferrer");
+ }}
+ >
+ <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
+ <OpenAI className="size-4 text-neutral-600" />
+ </div>
+ <div className="flex flex-1 flex-col items-start">
+ <div className="flex items-center gap-1">
+ <span className="font-medium">Open in ChatGPT</span>
+ <ArrowUpRight className="size-3.5 text-neutral-600" />
+ </div>
+ <span className="text-xs text-neutral-500">
+ Ask questions about this step
+ </span>
+ </div>
+ </button>
+
+ <button
+ className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
+ onClick={() => {
+ const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
+ window.open(claudeUrl, "_blank", "noopener,noreferrer");
+ }}
+ >
+ <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
+ <Anthropic className="size-4 text-neutral-600" />
+ </div>
+ <div className="flex flex-1 flex-col items-start">
+ <div className="flex items-center gap-1">
+ <span className="font-medium">Open in Claude</span>
+ <ArrowUpRight className="size-3.5 text-neutral-600" />
+ </div>
+ <span className="text-xs text-neutral-500">
+ Ask questions about this step
+ </span>
+ </div>
+ </button>
+ </div>
+ }
+ align="end"
+ openPopover={openDropdown}
+ setOpenPopover={setOpenDropdown}
+ >
+ <button
+ onClick={() => setOpenDropdown(!openDropdown)}
+ className={cn(
+ "flex h-8 items-center justify-center rounded-none border-0 bg-white px-2 transition-colors",
+ "hover:bg-neutral-50 focus-visible:ring-2 focus-visible:ring-black/50",
+ openDropdown && "bg-neutral-50",
+ )}
+ >
+ <ChevronDown className="size-3.5 text-neutral-600" />
+ </button>
+ </Popover>
+ </div>
+ );
+};
diff --git a/apps/web/ui/guides/guide-selector.tsx b/apps/web/ui/guides/guide-selector.tsx
new file mode 100644
index 0000000000..bab20b4b3f
--- /dev/null
+++ b/apps/web/ui/guides/guide-selector.tsx
@@ -0,0 +1,123 @@
+import { Combobox, ComboboxOption } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useMemo, useState } from "react";
+import { IntegrationGuide } from "./integrations";
+
+interface GuideSelectorProps {
+ value: IntegrationGuide | null;
+ guides: IntegrationGuide[];
+ onChange: (guide: IntegrationGuide) => void;
+ disabled?: boolean;
+ className?: string;
+}
+
+const GuideSelectorIcon = ({
+ icon: Icon,
+ fullSize,
+ className,
+}: { icon: any; className?: string } & IntegrationGuide["iconProps"]) => {
+ const containerClassName =
+ "size-8 shrink-0 overflow-hidden rounded-lg bg-white";
+ if (fullSize) {
+ return (
+ <Icon className={cn(containerClassName)} width="auto" height="100%" />
+ );
+ }
+
+ return (
+ <div
+ className={cn(
+ "flex items-center justify-center border border-neutral-200",
+ containerClassName,
+ )}
+ >
+ <Icon className="size-5" />
+ </div>
+ );
+ // return (
+ // <div
+ // className={cn(
+ // "flex aspect-square grow items-center justify-center self-stretch ",
+ // className,
+ // )}
+ // >
+ // <Icon
+ // className={cn("h-full w-full object-contain", fullSize ? "" : "p-1")}
+ // />
+ // </div>
+ // );
+};
+
+export function GuideSelector({
+ value,
+ guides,
+ onChange,
+ disabled,
+ className,
+}: GuideSelectorProps) {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ const guideOptions: ComboboxOption<IntegrationGuide>[] = useMemo(() => {
+ return guides?.map((guide) => ({
+ value: guide.key,
+ label: guide.title,
+ icon: (
+ <GuideSelectorIcon icon={guide.icon} {...(guide.iconProps || {})} />
+ ),
+ badge: guide.recommended ? "Recommended" : undefined,
+ description: guide.subtitle,
+ }));
+ }, [guides, value]);
+
+ const selectedOption = useMemo(() => {
+ if (!value) return null;
+
+ return guideOptions.find((g) => g.value === value.key) || null;
+ }, [value, guideOptions]);
+
+ return (
+ <Combobox
+ options={guideOptions}
+ setSelected={(option) => {
+ if (option && option.value) {
+ const guide = guides.find((guide) => guide.key === option.value);
+
+ if (guide) {
+ onChange(guide);
+ }
+ }
+ }}
+ selected={selectedOption}
+ icon={selectedOption?.icon}
+ caret={true}
+ placeholder={"Select guide"}
+ // searchPlaceholder="Search guides..."
+ // onSearchChange={setSearch}
+ // shouldFilter={}
+ matchTriggerWidth
+ open={openPopover}
+ onOpenChange={setOpenPopover}
+ popoverProps={{
+ contentClassName: "min-w-[280px]",
+ }}
+ labelProps={{
+ className: "text-sm font-semibold text-neutral-900",
+ }}
+ iconProps={
+ {
+ // className: "h-full",
+ }
+ }
+ buttonProps={{
+ disabled,
+ className: cn(
+ "w-fit p-1 transition-none rounded-lg bg-transparent hover:bg-neutral-200 border-none h-auto",
+ className,
+ ),
+ }}
+ hideSearch
+ >
+ {selectedOption?.label || "Select a guide"}
+ </Combobox>
+ );
+}
diff --git a/apps/web/ui/guides/guide.tsx b/apps/web/ui/guides/guide.tsx
index 36dad6b092..cf9b4b8dee 100644
--- a/apps/web/ui/guides/guide.tsx
+++ b/apps/web/ui/guides/guide.tsx
@@ -1,22 +1,10 @@
"use client";
-import {
- Anthropic,
- BookOpen,
- Button,
- buttonVariants,
- Check,
- ChevronLeft,
- OpenAI,
- Popover,
- useCopyToClipboard,
-} from "@dub/ui";
+import { Button, buttonVariants, ChevronLeft } from "@dub/ui";
import { cn } from "@dub/utils";
-import { ArrowUpRight, ChevronDown, Copy } from "lucide-react";
import Link from "next/link";
import { useParams, usePathname } from "next/navigation";
-import { useState } from "react";
-import { toast } from "sonner";
+import { GuideActionButton } from "./guide-action-button";
import { InstallStripeIntegrationButton } from "./install-stripe-integration-button";
import { guides, IntegrationType } from "./integrations";
import { GuidesMarkdown } from "./markdown";
@@ -32,15 +20,10 @@ export function Guide({ markdown }: { markdown: string }) {
const guideKey = guide[0];
const selectedGuide = guides.find((g) => g.key === guideKey)!;
const Icon = selectedGuide.icon;
- const [openDropdown, setOpenDropdown] = useState(false);
const pathname = usePathname();
const backHref = `${pathname.replace(`/${guideKey}`, "")}?step=${selectedGuide.type}`;
- const [copied, copyToClipboard] = useCopyToClipboard();
-
- const prompt = `Read from ${selectedGuide.url} so I can ask questions about it.`;
-
return (
<>
<hr className="mb-6 border-neutral-200" />
@@ -54,110 +37,7 @@ export function Guide({ markdown }: { markdown: string }) {
/>
</Link>
- <div className="flex items-center overflow-hidden rounded-lg border border-neutral-200">
- <Link
- href={selectedGuide.url}
- target="_blank"
- rel="noopener noreferrer"
- >
- <Button
- text="Read full guide"
- variant="secondary"
- className="h-8 rounded-none border-0 px-3"
- icon={<BookOpen className="size-3.5" />}
- />
- </Link>
-
- <div className="h-8 w-px bg-neutral-200" />
-
- <Popover
- content={
- <div className="flex w-full flex-col space-y-px rounded-lg bg-white p-1 sm:min-w-64">
- <button
- className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={() =>
- copyToClipboard(markdown, {
- onSuccess: () => {
- toast.success("Content copied as markdown");
- },
- })
- }
- >
- <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
- {copied ? (
- <Check className="size-4 text-neutral-600" />
- ) : (
- <Copy className="size-4 text-neutral-600" />
- )}
- </div>
- <div className="flex flex-col items-start">
- <span className="font-medium">Copy content</span>
- <span className="text-xs text-neutral-500">
- Copy page as Markdown for LLMs
- </span>
- </div>
- </button>
-
- <button
- className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={() => {
- const chatgptUrl = `https://chatgpt.com?hints=search&prompt=${encodeURIComponent(prompt)}`;
- console.log("chatgptUrl", chatgptUrl);
- window.open(chatgptUrl, "_blank", "noopener,noreferrer");
- }}
- >
- <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
- <OpenAI className="size-4 text-neutral-600" />
- </div>
- <div className="flex flex-1 flex-col items-start">
- <div className="flex items-center gap-1">
- <span className="font-medium">Open in ChatGPT</span>
- <ArrowUpRight className="size-3.5 text-neutral-600" />
- </div>
- <span className="text-xs text-neutral-500">
- Ask questions about this step
- </span>
- </div>
- </button>
-
- <button
- className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={() => {
- const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
- window.open(claudeUrl, "_blank", "noopener,noreferrer");
- }}
- >
- <div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
- <Anthropic className="size-4 text-neutral-600" />
- </div>
- <div className="flex flex-1 flex-col items-start">
- <div className="flex items-center gap-1">
- <span className="font-medium">Open in Claude</span>
- <ArrowUpRight className="size-3.5 text-neutral-600" />
- </div>
- <span className="text-xs text-neutral-500">
- Ask questions about this step
- </span>
- </div>
- </button>
- </div>
- }
- align="end"
- openPopover={openDropdown}
- setOpenPopover={setOpenDropdown}
- >
- <button
- onClick={() => setOpenDropdown(!openDropdown)}
- className={cn(
- "flex h-8 items-center justify-center rounded-none border-0 bg-white px-2 transition-colors",
- "hover:bg-neutral-50 focus-visible:ring-2 focus-visible:ring-black/50",
- openDropdown && "bg-neutral-50",
- )}
- >
- <ChevronDown className="size-3.5 text-neutral-600" />
- </button>
- </Popover>
- </div>
+ <GuideActionButton guide={selectedGuide} markdown={markdown} />
</div>
<div>
diff --git a/apps/web/ui/guides/icons/code-editor.tsx b/apps/web/ui/guides/icons/code-editor.tsx
index 1e6de6aa3b..2697eb4553 100644
--- a/apps/web/ui/guides/icons/code-editor.tsx
+++ b/apps/web/ui/guides/icons/code-editor.tsx
@@ -8,48 +8,49 @@ export function CodeEditor(props: SVGProps<SVGSVGElement>) {
viewBox="0 0 36 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
+ {...props}
>
<path
d="M6.33355 29.8892L29.6669 29.8892C32.1215 29.8892 34.1113 27.8993 34.1113 25.4447V6.55583C34.1113 4.10123 32.1215 2.11138 29.6669 2.11138L6.33355 2.11138C3.87895 2.11138 1.88911 4.10123 1.88911 6.55583V25.4447C1.88911 27.8993 3.87895 29.8892 6.33355 29.8892Z"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
<path
d="M9.66699 2.11133V29.8891"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
<path
d="M21.8887 18.7778H28.5553"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
<path
d="M18.5557 13.2227H24.6668"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
<path
d="M18.5557 24.3335H23.0001"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
<path
d="M15.2227 7.66699H18.556"
stroke="#404040"
- stroke-width="2.5"
- stroke-linecap="round"
- stroke-linejoin="round"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
/>
</svg>
);
diff --git a/apps/web/ui/guides/icons/stripe.tsx b/apps/web/ui/guides/icons/stripe.tsx
index 7d1c4abbc9..4091ec18bd 100644
--- a/apps/web/ui/guides/icons/stripe.tsx
+++ b/apps/web/ui/guides/icons/stripe.tsx
@@ -1,32 +1,29 @@
-import { SVGProps, useId } from "react";
+import { SVGProps } from "react";
export function Stripe(props: SVGProps<SVGSVGElement>) {
- const id = useId();
return (
<svg
- xmlns="http://www.w3.org/2000/svg"
- width="45"
- height="44"
+ width="32"
+ height="32"
+ viewBox="0 0 32 32"
fill="none"
- viewBox="0 0 45 44"
+ xmlns="http://www.w3.org/2000/svg"
{...props}
>
- <g
- fillRule="evenodd"
- clipPath={`url(#${id}-clip-path)`}
- clipRule="evenodd"
- >
- <path fill="#635BFF" d="M.667 0h44v44h-44z"></path>
- <path
- fill="#fff"
- d="M20.95 17.105c0-1.034.848-1.441 2.256-1.441 2.024 0 4.576.616 6.6 1.705V11.12c-2.212-.88-4.39-1.221-6.59-1.221-5.4 0-8.987 2.816-8.987 7.524 0 7.337 10.11 6.17 10.11 9.339 0 1.22-1.067 1.617-2.552 1.617-2.211 0-5.027-.902-7.26-2.123v6.325a18.4 18.4 0 0 0 7.26 1.518c5.533 0 9.339-2.74 9.339-7.502-.045-7.92-10.175-6.512-10.175-9.493"
- ></path>
- </g>
- <defs>
- <clipPath id={`${id}-clip-path`}>
- <rect width="44" height="44" x="0.667" fill="#fff" rx="6"></rect>
- </clipPath>
- </defs>
+ <path
+ d="M8 0.5H24C28.1421 0.5 31.5 3.85786 31.5 8V24C31.5 28.1421 28.1421 31.5 24 31.5H8C3.85786 31.5 0.5 28.1421 0.5 24V8C0.5 3.85786 3.85786 0.5 8 0.5Z"
+ fill="#543AFD"
+ />
+ <path
+ d="M8 0.5H24C28.1421 0.5 31.5 3.85786 31.5 8V24C31.5 28.1421 28.1421 31.5 24 31.5H8C3.85786 31.5 0.5 28.1421 0.5 24V8C0.5 3.85786 3.85786 0.5 8 0.5Z"
+ stroke="#E5E5E5"
+ />
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M9 11.8726L23 9V20.0943L9 23V11.9057V11.8726Z"
+ fill="white"
+ />
</svg>
);
}
diff --git a/apps/web/ui/guides/integrations.ts b/apps/web/ui/guides/integrations.ts
index 41e8f3076c..b071ab454d 100644
--- a/apps/web/ui/guides/integrations.ts
+++ b/apps/web/ui/guides/integrations.ts
@@ -23,11 +23,18 @@ export type IntegrationGuide = {
description?: string;
subtitle?: string;
icon: any;
+ iconProps?: {
+ fullSize?: boolean;
+ };
recommended?: boolean;
content?: string;
url: string;
};
+export type IntegrationGuideWithMarkdown = IntegrationGuide & {
+ markdown: string | null;
+};
+
export const sections: {
type: IntegrationType;
title: string;
@@ -181,6 +188,9 @@ export const guides: IntegrationGuide[] = [
recommended: true,
description: "Stripe Checkout",
icon: Stripe,
+ iconProps: {
+ fullSize: true,
+ },
url: "https://dub.co/docs/conversions/sales/stripe#option-2%3A-using-stripe-checkout-recommended",
},
{
@@ -190,6 +200,9 @@ export const guides: IntegrationGuide[] = [
subtitle: "Payment Links",
description: "Stripe Payment Links",
icon: Stripe,
+ iconProps: {
+ fullSize: true,
+ },
url: "https://dub.co/docs/conversions/sales/stripe#option-1%3A-using-stripe-payment-links",
},
{
@@ -199,6 +212,9 @@ export const guides: IntegrationGuide[] = [
subtitle: "Customers",
description: "Stripe Customers",
icon: Stripe,
+ iconProps: {
+ fullSize: true,
+ },
url: "https://dub.co/docs/conversions/sales/stripe#option-3%3A-using-stripe-customers",
},
{
diff --git a/apps/web/ui/layout/settings-layout.tsx b/apps/web/ui/layout/settings-layout.tsx
index 1ae348170c..48baee45a7 100644
--- a/apps/web/ui/layout/settings-layout.tsx
+++ b/apps/web/ui/layout/settings-layout.tsx
@@ -5,7 +5,7 @@ import { PageContentOld } from "./page-content";
export default function SettingsLayout({ children }: PropsWithChildren) {
return (
<PageContentOld>
- <div className="relative min-h-[calc(100vh-16px)]">
+ <div className="relative min-h-[calc(100vh-60px)] md:min-h-[calc(100vh-32px)]">
<MaxWidthWrapper className="grid grid-cols-1 gap-5 pb-10 pt-3">
{children}
</MaxWidthWrapper>
diff --git a/packages/tailwind-config/tailwind.config.ts b/packages/tailwind-config/tailwind.config.ts
index c81a9b5a73..c84b6f3fef 100644
--- a/packages/tailwind-config/tailwind.config.ts
+++ b/packages/tailwind-config/tailwind.config.ts
@@ -247,6 +247,9 @@ const config: Config = {
dropShadow: {
"card-hover": ["0 8px 12px #222A350d", "0 32px 80px #2f30370f"],
},
+ boxShadow: {
+ xs: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
+ },
},
},
plugins: [
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index 9510f32ea2..54bbd915fb 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -28,6 +28,8 @@ import { Tooltip } from "../tooltip";
export type ComboboxOption<TMeta = any> = {
label: string | ReactNode;
+ description?: string;
+ badge?: string;
value: string;
icon?: Icon | ReactNode;
disabledTooltip?: ReactNode;
@@ -331,15 +333,22 @@ export function Combobox({
)}
text={
<>
- <div
- className={cn(
- "min-w-0 grow truncate text-left",
- labelProps?.className,
+ <div>
+ <div
+ className={cn(
+ "min-w-0 grow truncate text-left",
+ labelProps?.className,
+ )}
+ >
+ {children ||
+ selected.map((option) => option.label).join(", ") ||
+ placeholder}
+ </div>
+ {selected.length === 1 && selected[0].description && (
+ <div className="text-content-subtle text-xs font-medium">
+ {selected[0].description}
+ </div>
)}
- >
- {children ||
- selected.map((option) => option.label).join(", ") ||
- placeholder}
</div>
{caret &&
(caret === true ? (
@@ -414,7 +423,22 @@ function Option({
)}
</span>
)}
- <span className="grow truncate">{option.label}</span>
+ <div>
+ <div className="flex items-center gap-1.5">
+ <span className="grow truncate">{option.label}</span>
+
+ {option.badge && (
+ <span className="min-h-4 rounded-md bg-violet-100 px-1 text-xs font-semibold text-violet-600">
+ {option.badge}
+ </span>
+ )}
+ </div>
+ {option.description && (
+ <div className="text-content-subtle text-xs font-medium">
+ {option.description}
+ </div>
+ )}
+ </div>
</div>
{right}
{!multiple && selected && (
diff --git a/packages/ui/src/icons/index.tsx b/packages/ui/src/icons/index.tsx
index f62e1d3556..02f95d0d8c 100644
--- a/packages/ui/src/icons/index.tsx
+++ b/packages/ui/src/icons/index.tsx
@@ -15,6 +15,7 @@ export * from "./dub-partners";
export * from "./dub-product-icon";
export * from "./expanding-arrow";
export * from "./ios-app-store";
+export * from "./lock-small";
export * from "./magic";
export * from "./markdown-icon";
export * from "./matrix-lines";
diff --git a/packages/ui/src/icons/lock-small.tsx b/packages/ui/src/icons/lock-small.tsx
new file mode 100644
index 0000000000..62577815c6
--- /dev/null
+++ b/packages/ui/src/icons/lock-small.tsx
@@ -0,0 +1,30 @@
+import { SVGProps } from "react";
+
+export function LockSmall(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ width="8"
+ height="8"
+ viewBox="0 0 8 8"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g clipPath="url(#clip0_2161_2140)">
+ <path
+ d="M5.5 4C5.224 4 5 3.776 5 3.5V2C5 1.44867 4.55133 1 4 1C3.44867 1 3 1.44867 3 2V3.5C3 3.776 2.776 4 2.5 4C2.224 4 2 3.776 2 3.5V2C2 0.897333 2.89733 0 4 0C5.10267 0 6 0.897333 6 2V3.5C6 3.776 5.776 4 5.5 4Z"
+ fill="black"
+ />
+ <path
+ d="M6.16665 3H1.83331C1.00598 3 0.333313 3.67267 0.333313 4.5V6.5C0.333313 7.32733 1.00598 8 1.83331 8H6.16665C6.99398 8 7.66665 7.32733 7.66665 6.5V4.5C7.66665 3.67267 6.99398 3 6.16665 3ZM4.49998 5.83333C4.49998 6.10933 4.27598 6.33333 3.99998 6.33333C3.72398 6.33333 3.49998 6.10933 3.49998 5.83333V5.16667C3.49998 4.89067 3.72398 4.66667 3.99998 4.66667C4.27598 4.66667 4.49998 4.89067 4.49998 5.16667V5.83333Z"
+ fill="black"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_2161_2140">
+ <rect width="8" height="8" fill="white" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}
diff --git a/packages/utils/src/functions/index.ts b/packages/utils/src/functions/index.ts
index a0a17a2b42..5ea4ca5f59 100644
--- a/packages/utils/src/functions/index.ts
+++ b/packages/utils/src/functions/index.ts
@@ -30,6 +30,7 @@ export * from "./regex-escape";
export * from "./resize-image";
export * from "./smart-truncate";
export * from "./stable-sort";
+export * from "./text-fetcher";
export * from "./time-ago";
export * from "./trim";
export * from "./truncate";
diff --git a/packages/utils/src/functions/text-fetcher.ts b/packages/utils/src/functions/text-fetcher.ts
new file mode 100644
index 0000000000..02b81f5114
--- /dev/null
+++ b/packages/utils/src/functions/text-fetcher.ts
@@ -0,0 +1,27 @@
+interface SWRError extends Error {
+ info: any;
+ status: number;
+}
+
+export async function textFetcher(
+ input: RequestInfo,
+ init?: RequestInit & { headers?: Record<string, string> },
+): Promise<string> {
+ const res = await fetch(input, {
+ ...init,
+ ...(init?.headers && { headers: init.headers }),
+ });
+
+ if (!res.ok) {
+ const message =
+ (await res.json())?.error?.message ||
+ "An error occurred while fetching the data.";
+ const error = new Error(message) as SWRError;
+ error.info = message;
+ error.status = res.status;
+
+ throw error;
+ }
+
+ return res.text();
+}