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.

Only send usage summary email if workspace has at least 1 click

Steven Tey5357d75a8efe
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index 494bf6643c..9b03809fd6 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -100,53 +100,54 @@ export const updateUsage = async () => {
},
});
- // Only send the 30-day summary email if the workspace was created more than 30 days ago
+ /* Only send the 30-day summary email if:
+ - the workspace has at least 1 link click
+ - the workspace was created more than 30 days ago
+ */
if (
+ workspace.usage > 0 &&
workspace.createdAt.getTime() <
- new Date().getTime() - 30 * 24 * 60 * 60 * 1000
+ new Date().getTime() - 30 * 24 * 60 * 60 * 1000
) {
- const topLinks =
- workspace.usage > 0
- ? await getAnalytics({
- workspaceId: workspace.id,
- event: "clicks",
- groupBy: "top_links",
- interval: "30d",
- root: false,
- }).then(async (data) => {
- const topFive = data.slice(0, 5);
- return await Promise.all(
- topFive.map(
- async ({
- link: linkId,
- clicks,
- }: {
- link: string;
- clicks: number;
- }) => {
- const link = await prisma.link.findUnique({
- where: {
- id: linkId,
- },
- select: {
- domain: true,
- key: true,
- },
- });
- if (!link) return;
- return {
- link: linkConstructor({
- domain: link.domain,
- key: link.key,
- pretty: true,
- }),
- clicks,
- };
- },
- ),
- );
- })
- : [];
+ const topLinks = await getAnalytics({
+ workspaceId: workspace.id,
+ event: "clicks",
+ groupBy: "top_links",
+ interval: "30d",
+ root: false,
+ }).then(async (data) => {
+ const topFive = data.slice(0, 5);
+ return await Promise.all(
+ topFive.map(
+ async ({
+ link: linkId,
+ clicks,
+ }: {
+ link: string;
+ clicks: number;
+ }) => {
+ const link = await prisma.link.findUnique({
+ where: {
+ id: linkId,
+ },
+ select: {
+ domain: true,
+ key: true,
+ },
+ });
+ if (!link) return;
+ return {
+ link: linkConstructor({
+ domain: link.domain,
+ key: link.key,
+ pretty: true,
+ }),
+ clicks,
+ };
+ },
+ ),
+ );
+ });
const emails = workspace.users.map(
(user) => user.user.email,