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.

Improved 30-day summary email and cadence

Steven Teyaadcbe9d660e
diff --git a/emails/clicks-summary.tsx b/emails/clicks-summary.tsx
index fb571fa15e..dff97c5b03 100644
--- a/emails/clicks-summary.tsx
+++ b/emails/clicks-summary.tsx
@@ -55,6 +55,7 @@ export default function ClicksSummary({
clicks: number;
}[];
}) {
+ const inactiveUser = createdLinks === 0;
return (
<Html>
<Head />
@@ -133,17 +134,38 @@ export default function ClicksSummary({
</Section>
</>
)}
- <Text className="mt-10 text-sm leading-6 text-black">
- You can view your full stats by clicking the button below.
- </Text>
- <Section className="my-8 text-center">
- <Link
- className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
- href={`https://app.dub.sh/${projectSlug}?sort=clicks`}
- >
- View my stats
- </Link>
- </Section>
+ {inactiveUser ? (
+ <>
+ <Text className="text-sm leading-6 text-black">
+ It looks like you haven't created any links in the last 30
+ days. If there's anything that we can do to help, please reply
+ to this email to get in touch with us.
+ </Text>
+
+ <Section className="my-8 text-center">
+ <Link
+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={`https://app.dub.sh/${projectSlug}`}
+ >
+ Start creating links
+ </Link>
+ </Section>
+ </>
+ ) : (
+ <>
+ <Text className="mt-10 text-sm leading-6 text-black">
+ You can view your full stats by clicking the button below.
+ </Text>
+ <Section className="my-8 text-center">
+ <Link
+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={`https://app.dub.sh/${projectSlug}?sort=clicks`}
+ >
+ View my stats
+ </Link>
+ </Section>
+ </>
+ )}
<Hr className="mx-0 my-6 w-full border border-gray-200" />
<Text className="text-[12px] leading-6 text-gray-500">
This email was intended for members of the{" "}
diff --git a/lib/cron/usage.tsx b/lib/cron/usage.tsx
index 75893afb85..c3cab18761 100644
--- a/lib/cron/usage.tsx
+++ b/lib/cron/usage.tsx
@@ -36,6 +36,7 @@ export const updateUsage = async () => {
},
},
sentEmails: true,
+ createdAt: true,
},
});
@@ -90,40 +91,45 @@ export const updateUsage = async () => {
// Reset usage for projects that have billingCycleStart today
// also delete sentEmails for those projects
- // TODO: Monthly summary emails (total clicks, best performing links, etc.)
const resetBillingResponse = await Promise.allSettled(
billingReset.map(async (project) => {
- const [createdLinks, topLinks] = await Promise.allSettled([
- prisma.link.count({
- where: {
- project: {
- id: project.id,
- },
- createdAt: {
- // in the last 30 days
- gte: new Date(new Date().setDate(new Date().getDate() - 30)),
+ // Only send the 30-day summary email if the project was created more than 30 days ago
+ if (
+ project.createdAt.getTime() <
+ new Date().getTime() - 30 * 24 * 60 * 60 * 1000
+ ) {
+ const [createdLinks, topLinks] = await Promise.allSettled([
+ prisma.link.count({
+ where: {
+ project: {
+ id: project.id,
+ },
+ createdAt: {
+ // in the last 30 days
+ gte: new Date(new Date().setDate(new Date().getDate() - 30)),
+ },
},
- },
- }),
- getTopLinks(project.domains.map((domain) => domain.slug)),
- ]);
+ }),
+ getTopLinks(project.domains.map((domain) => domain.slug)),
+ ]);
- const emails = project.users.map((user) => user.user.email) as string[];
+ const emails = project.users.map((user) => user.user.email) as string[];
- limiter.schedule(() =>
- sendEmail({
- subject: `Your 30-day Dub summary for ${project.name}`,
- email: emails,
- react: ClicksSummary({
- projectName: project.name,
- projectSlug: project.slug,
- totalClicks: project.usage,
- createdLinks:
- createdLinks.status === "fulfilled" ? createdLinks.value : 0,
- topLinks: topLinks.status === "fulfilled" ? topLinks.value : [],
+ limiter.schedule(() =>
+ sendEmail({
+ subject: `Your 30-day Dub summary for ${project.name}`,
+ email: emails,
+ react: ClicksSummary({
+ projectName: project.name,
+ projectSlug: project.slug,
+ totalClicks: project.usage,
+ createdLinks:
+ createdLinks.status === "fulfilled" ? createdLinks.value : 0,
+ topLinks: topLinks.status === "fulfilled" ? topLinks.value : [],
+ }),
}),
- }),
- );
+ );
+ }
return await prisma.project.update({
where: {