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.

Dub Wrapped

Steven Tey78dfadc9d73b
diff --git a/apps/web/emails/clicks-summary.tsx b/apps/web/emails/clicks-summary.tsx
index 0a05cd60d9..afd128cfc6 100644
--- a/apps/web/emails/clicks-summary.tsx
+++ b/apps/web/emails/clicks-summary.tsx
@@ -142,7 +142,7 @@ export default function ClicksSummary({
align="right"
className="text-sm text-gray-600"
>
- {nFormatter(clicks)}
+ {nFormatter(clicks, { full: clicks < 99999 })}
</Column>
</Row>
{index !== topLinks.length - 1 && (
diff --git a/apps/web/emails/components/footer.tsx b/apps/web/emails/components/footer.tsx
index 5e97b42170..653dd04a8d 100644
--- a/apps/web/emails/components/footer.tsx
+++ b/apps/web/emails/components/footer.tsx
@@ -15,7 +15,6 @@ export default function Footer({
<Hr className="mx-0 my-6 w-full border border-gray-200" />
<Text className="text-[12px] leading-6 text-gray-500">
We send out product update emails once a month – no spam, no nonsense.
- <br />
Don't want to get these emails?{" "}
<Link
className="text-gray-700 underline"
@@ -24,6 +23,13 @@ export default function Footer({
Unsubscribe here.
</Link>
</Text>
+ <Text className="text-[12px] text-gray-500">
+ Dub Technologies, Inc.
+ <br />
+ 2261 Market Street STE 5906
+ <br />
+ San Francisco, CA 941114
+ </Text>
</Tailwind>
);
}
@@ -49,6 +55,13 @@ export default function Footer({
</Link>
</Text>
)}
+ <Text className="text-[12px] text-gray-500">
+ Dub Technologies, Inc.
+ <br />
+ 2261 Market Street STE 5906
+ <br />
+ San Francisco, CA 941114
+ </Text>
</Tailwind>
);
}
diff --git a/apps/web/emails/dub-wrapped.tsx b/apps/web/emails/dub-wrapped.tsx
new file mode 100644
index 0000000000..bf13949da3
--- /dev/null
+++ b/apps/web/emails/dub-wrapped.tsx
@@ -0,0 +1,461 @@
+import { COUNTRIES, DUB_WORDMARK, smartTruncate } from "@dub/utils";
+import { nFormatter } from "@dub/utils/src/functions";
+import {
+ Body,
+ Column,
+ Container,
+ Head,
+ Heading,
+ Hr,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Row,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import Footer from "./components/footer";
+
+export default function DubWrapped({
+ email = "[email protected]",
+ workspace = {
+ name: "Dub",
+ slug: "dub",
+ logo: "https://assets.dub.co/logo.png",
+ },
+ stats = {
+ "Total Links": 1429,
+ "Total Clicks": 425319,
+ },
+ topLinks = [
+ {
+ item: "dub.sh/link",
+ count: 13923,
+ },
+ {
+ item: "dub.sh/link",
+ count: 2225,
+ },
+ {
+ item: "dub.sh/link",
+ count: 423,
+ },
+ {
+ item: "dub.sh/link",
+ count: 325,
+ },
+ {
+ item: "dub.sh/link",
+ count: 233,
+ },
+ ],
+ topCountries = [
+ {
+ item: "US",
+ count: 23049,
+ },
+ {
+ item: "GB",
+ count: 12345,
+ },
+ {
+ item: "CA",
+ count: 10000,
+ },
+ {
+ item: "DE",
+ count: 9000,
+ },
+ {
+ item: "FR",
+ count: 8000,
+ },
+ ],
+}: {
+ email: string;
+ workspace: {
+ name: string;
+ slug: string;
+ logo: string;
+ };
+ stats: {
+ "Total Links": number;
+ "Total Clicks": number;
+ };
+ topLinks: {
+ item: string;
+ count: number;
+ }[];
+ topCountries: {
+ item: string;
+ count: number;
+ }[];
+}) {
+ const dubStats = [
+ {
+ item: "125M clicks tracked",
+ increase: "+900%",
+ },
+ {
+ item: "715K links created",
+ increase: "+400%",
+ },
+ {
+ item: "65K new users",
+ increase: "+250%",
+ },
+ {
+ item: "4.4K domains added",
+ increase: "+400%",
+ },
+ ];
+
+ const shippedItems = [
+ {
+ title: "Free .LINK domains on all paid plans",
+ description:
+ "We partnered with Nova Registry to offer a <b>1-year free .link domain</b> to all paying Dub customers. By using a custom domain, you get <b>30% higher click-through rates</b>.",
+ image: "https://assets.dub.co/blog/free-dot-link.jpg",
+ cta: {
+ text: "Read the announcement",
+ href: "https://dub.co/blog/introducing-free-domains",
+ },
+ },
+ {
+ title: "New link builder + dashboard",
+ description:
+ "We launched a new link builder, rebuilt from the ground up, to help you manage your links better. We also gave our dashboard a makeover as well.",
+ image: "https://assets.dub.co/changelog/new-dashboard.jpg",
+ cta: {
+ text: "Read the announcement",
+ href: "https://dub.co/blog/new-link-builder",
+ },
+ },
+ {
+ title: "Dub Integrations",
+ description:
+ "We added integrations with <b>Slack</b>, <b>Notion</b>, <b>Google Sheets</b> and <b>Google Docs</b>. Our API also went GA",
+ image: "https://assets.dub.co/blog/integrations.jpg",
+ cta: {
+ text: "Read the announcement",
+ href: "https://dub.co/blog/introducing-dub-integrations",
+ },
+ },
+ ];
+
+ return (
+ <Html>
+ <Head />
+ <Preview>Dub Wrapped</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img src={DUB_WORDMARK} height="32" alt="Dub" className="my-0" />
+ </Section>
+ <Heading className="mx-0 mb-4 mt-8 p-0 text-xl font-semibold text-black">
+ Dub Year in Review 🎊
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Thank you for your support and here's to another year of your
+ activity on Dub! Here's a look back at your activity in 2024.
+ </Text>
+
+ <Section className="my-8 rounded-lg border border-solid border-gray-200 p-2">
+ <div className="relative">
+ <div className="absolute inset-0 flex flex-col items-center justify-center pt-4">
+ <Img src={workspace.logo} height="36" alt={workspace.name} />
+ <Text className="mt-1 text-xl font-semibold">
+ {workspace.name}
+ </Text>
+ </div>
+ <SectionHeaderBackground />
+ </div>
+ <div className="grid grid-cols-2 gap-2 px-4 py-2">
+ {Object.entries(stats).map(([key, value]) => (
+ <StatCard key={key} title={key} value={value} />
+ ))}
+ </div>
+ <div className="grid gap-2 px-4">
+ <StatTable
+ title="Top Links"
+ value={topLinks}
+ workspaceSlug={workspace.slug}
+ />
+ <StatTable
+ title="Top Countries"
+ value={topCountries}
+ workspaceSlug={workspace.slug}
+ />
+ </div>
+ </Section>
+
+ <Heading className="mx-0 mb-4 mt-8 p-0 text-xl font-semibold text-black">
+ Your contribution 📈
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Thanks to customers like you, we had an incredible year as well,
+ seeing record activity and link clicks.
+ </Text>
+ {dubStats.map((stat) => (
+ <Text
+ key={stat.item}
+ className="ml-1 text-sm font-medium leading-4 text-black"
+ >
+ ◆ {stat.item}{" "}
+ <span className="font-semibold text-green-700">
+ ({stat.increase})
+ </span>
+ </Text>
+ ))}
+ <Img
+ src="https://assets.dub.co/misc/thank-you-thumbnail.jpg"
+ alt="Thank you"
+ className="max-w-[500px] rounded-lg"
+ />
+
+ <Hr className="mx-0 my-6 w-full border border-gray-200" />
+
+ <Heading className="mx-0 mb-4 mt-8 p-0 text-xl font-semibold text-black">
+ What we shipped 🚢
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Here's a look back at what we shipped in 2024.
+ </Text>
+
+ {shippedItems.map((item) => (
+ <div key={item.title} className="mb-8">
+ <Img
+ src={item.image}
+ alt={item.title}
+ className="max-w-[500px] rounded-lg"
+ />
+ <Text className="text-lg font-semibold text-black">
+ {item.title}
+ </Text>
+ <Text
+ className="leading-6 text-gray-600"
+ dangerouslySetInnerHTML={{ __html: item.description }}
+ />
+ <Link
+ href={item.cta.href}
+ className="rounded-md bg-black px-4 py-1.5 text-sm font-medium text-white"
+ >
+ {item.cta.text}
+ </Link>
+ </div>
+ ))}
+
+ <Hr className="mx-0 my-6 w-full border border-gray-200" />
+
+ <Text className="text-sm leading-6 text-black">
+ Thank you again, and happy holidays!
+ </Text>
+ <Img
+ src="https://assets.dub.co/misc/email-signature.png"
+ alt="Email signature"
+ className="max-w-[200px]"
+ />
+ <Text className="text-sm leading-6 text-black">
+ and everyone at the Dub team 🎄
+ </Text>
+
+ <Footer email={email} marketing />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
+
+const StatCard = ({
+ title,
+ value,
+}: {
+ title: string;
+ value: number | string;
+}) => {
+ return (
+ <div>
+ <Text className="font-medium text-gray-400">{title}</Text>
+ <Text className="-mt-3 text-lg font-medium text-black">
+ {typeof value === "number" ? nFormatter(value, { full: true }) : value}
+ </Text>
+ </div>
+ );
+};
+
+const StatTable = ({
+ title,
+ value,
+ workspaceSlug,
+}: {
+ title: string;
+ value: { item: string; count: number }[];
+ workspaceSlug: string;
+}) => {
+ return (
+ <Section>
+ <Text className="mb-0 font-medium text-gray-400">{title}</Text>
+ {value.map(({ item, count }, index) => {
+ const [domain, ...pathParts] = item.split("/");
+ const path = pathParts.join("/") || "_root";
+ return (
+ <div key={index} className="text-sm">
+ <Row>
+ <Column align="left">
+ {title === "Top Links" ? (
+ <div className="py-2">
+ <Link
+ href={`https://app.dub.co/${workspaceSlug}/analytics?domain=${domain}&key=${path}&interval=1y`}
+ className="font-medium text-black underline underline-offset-2"
+ >
+ {smartTruncate(item, 33)} ↗
+ </Link>
+ </div>
+ ) : (
+ <div className="flex items-center gap-2">
+ <img
+ src={`https://hatscripts.github.io/circle-flags/flags/${item.toLowerCase()}.svg`}
+ alt={COUNTRIES[item]}
+ height="16"
+ />
+ <p>{COUNTRIES[item]}</p>
+ </div>
+ )}
+ </Column>
+ <Column align="right" className="text-gray-600">
+ {nFormatter(count, { full: count < 99999 })}
+ </Column>
+ </Row>
+ {index !== value.length - 1 && (
+ <Hr className="my-0 w-full border border-gray-200" />
+ )}
+ </div>
+ );
+ })}
+ </Section>
+ );
+};
+
+const SectionHeaderBackground = () => {
+ return (
+ <svg
+ width="484"
+ height="111"
+ viewBox="0 0 484 111"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <g clip-path="url(#clip0_470_90)">
+ <rect width="484" height="111" rx="8" fill="#FAFAFA" />
+ <rect x="-10" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="32" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="74" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="116" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="158" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="200" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="242" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="284" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="326" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="368" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="410" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="452" y="-7" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="-10" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="32" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="74" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="116" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="158" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="200" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="242" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="284" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="326" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="368" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="410" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="452" y="35" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="-10" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="32" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="74" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="116" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="158" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="200" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="242" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="284" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="326" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="368" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="410" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect x="452" y="77" width="42" height="42" stroke="#E5E5E5" />
+ <rect
+ y="29"
+ width="484"
+ height="82"
+ fill="url(#paint0_linear_470_90)"
+ />
+ <g opacity="0.2" filter="url(#filter0_f_470_90)">
+ <ellipse
+ cx="241.5"
+ cy="64.5"
+ rx="181.5"
+ ry="42.5"
+ transform="rotate(180 241.5 64.5)"
+ fill="url(#paint1_angular_470_90)"
+ />
+ </g>
+ </g>
+ <defs>
+ <filter
+ id="filter0_f_470_90"
+ x="-40"
+ y="-78"
+ width="563"
+ height="285"
+ filterUnits="userSpaceOnUse"
+ color-interpolation-filters="sRGB"
+ >
+ <feFlood flood-opacity="0" result="BackgroundImageFix" />
+ <feBlend
+ mode="normal"
+ in="SourceGraphic"
+ in2="BackgroundImageFix"
+ result="shape"
+ />
+ <feGaussianBlur
+ stdDeviation="50"
+ result="effect1_foregroundBlur_470_90"
+ />
+ </filter>
+ <linearGradient
+ id="paint0_linear_470_90"
+ x1="242"
+ y1="29"
+ x2="242"
+ y2="111"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stop-color="#FAFAFA" stop-opacity="0" />
+ <stop offset="1" stop-color="#FAFAFA" />
+ </linearGradient>
+ <radialGradient
+ id="paint1_angular_470_90"
+ cx="0"
+ cy="0"
+ r="1"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(241.5 64.5) rotate(-159.856) scale(84.7412 60.41)"
+ >
+ <stop stop-color="#FF0000" />
+ <stop offset="0.275102" stop-color="#EAB308" />
+ <stop offset="0.450298" stop-color="#5CFF80" />
+ <stop offset="0.6" stop-color="#00FFF9" />
+ <stop offset="0.8" stop-color="#3A8BFD" />
+ <stop offset="1" stop-color="#855AFC" />
+ </radialGradient>
+ <clipPath id="clip0_470_90">
+ <rect width="484" height="111" rx="8" fill="white" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+};
diff --git a/apps/web/scripts/dub-wrapped.ts b/apps/web/scripts/dub-wrapped.ts
new file mode 100644
index 0000000000..4a6423525c
--- /dev/null
+++ b/apps/web/scripts/dub-wrapped.ts
@@ -0,0 +1,98 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import { AnalyticsCountries, AnalyticsTopLinks } from "dub/models/components";
+import { getAnalytics } from "../lib/analytics/get-analytics";
+
+async function main() {
+ const seeded = await prisma.yearInReview
+ .findMany({
+ where: {
+ year: 2024,
+ },
+ select: {
+ workspaceId: true,
+ },
+ })
+ .then((data) => data.map(({ workspaceId }) => workspaceId));
+
+ // get projects with links created in 2024 and have clicks
+ const data = await prisma.link
+ .groupBy({
+ by: ["projectId"],
+ where: {
+ createdAt: {
+ gte: new Date("2024-01-01"),
+ lte: new Date("2024-12-31"),
+ },
+ AND: [
+ {
+ projectId: {
+ not: null,
+ },
+ },
+ {
+ projectId: {
+ notIn: seeded,
+ },
+ },
+ ],
+ },
+ _count: {
+ id: true,
+ },
+ _sum: {
+ clicks: true,
+ },
+ orderBy: {
+ _count: {
+ id: "desc",
+ },
+ },
+ take: 10,
+ })
+ // only get projects with more than 5 links created in 2024
+ .then((data) => data.filter(({ _count }) => _count.id > 5));
+
+ const payloads = await Promise.all(
+ data.map(async ({ projectId, _count, _sum }) => {
+ const [topLinks, topCountries] = (await Promise.all([
+ getAnalytics({
+ workspaceId: projectId!,
+ event: "clicks",
+ groupBy: "top_links",
+ interval: "ytd",
+ root: false,
+ }),
+ getAnalytics({
+ workspaceId: projectId!,
+ event: "clicks",
+ groupBy: "countries",
+ interval: "ytd",
+ }),
+ ])) as [AnalyticsTopLinks[], AnalyticsCountries[]];
+
+ return {
+ year: 2024,
+ workspaceId: projectId!,
+ totalLinks: _count.id,
+ totalClicks: _sum.clicks ?? 0,
+ topLinks: topLinks.slice(0, 5).map(({ domain, key, clicks }) => ({
+ item: `${domain}/${key}`,
+ count: clicks,
+ })),
+ topCountries: topCountries.slice(0, 5).map(({ country, clicks }) => ({
+ item: country,
+ count: clicks,
+ })),
+ };
+ }),
+ );
+
+ console.table(payloads);
+
+ await prisma.yearInReview.createMany({
+ data: payloads,
+ });
+}
+
+main();
diff --git a/packages/prisma/schema/misc.prisma b/packages/prisma/schema/misc.prisma
new file mode 100644
index 0000000000..144b9e8cdd
--- /dev/null
+++ b/packages/prisma/schema/misc.prisma
@@ -0,0 +1,18 @@
+model YearInReview {
+ id String @id @default(cuid())
+ year Int
+
+ totalLinks Int
+ totalClicks Int
+ topLinks Json
+ topCountries Json
+
+ workspaceId String
+ workspace Project @relation(fields: [workspaceId], references: [id])
+
+ createdAt DateTime @default(now())
+ sentAt DateTime?
+
+ @@unique([year])
+ @@index([workspaceId])
+}
diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prisma
index 18cd572653..de9d925fe5 100644
--- a/packages/prisma/schema/workspace.prisma
+++ b/packages/prisma/schema/workspace.prisma
@@ -55,6 +55,7 @@ model Project {
registeredDomains RegisteredDomain[]
dashboards Dashboard[]
utmTemplates UtmTemplate[]
+ yearInReviews YearInReview[]
@@index(usageLastChecked(sort: Asc))
}