Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Swetrix email reminder

Blue Mousedf8102bf9f01
diff --git a/backend/apps/cloud/src/common/templates/en/no-events-after-signup.html b/backend/apps/cloud/src/common/templates/en/no-events-after-signup.html
new file mode 100644
index 000000000..b56ba034f
--- /dev/null
+++ b/backend/apps/cloud/src/common/templates/en/no-events-after-signup.html
@@ -0,0 +1,16 @@
+Hi there,
+<br />
+<br />
+Thanks for signing up for Swetrix.
+<br />
+We noticed your project has not received its first event yet. Most setups are
+done in a few minutes.
+<br />
+<br />
+<a href="{{dashboardUrl}}" target="_blank">Go to dashboard</a>
+<br />
+Need help setting it up?
+<a href="{{setupGuideUrl}}" target="_blank">Open the setup guide</a>
+<br />
+<br />
+If you want, reply to this email and we can help you validate the installation.
diff --git a/backend/apps/cloud/src/mailer/letter.ts b/backend/apps/cloud/src/mailer/letter.ts
index c804de7d4..b8a1cb801 100644
--- a/backend/apps/cloud/src/mailer/letter.ts
+++ b/backend/apps/cloud/src/mailer/letter.ts
@@ -19,4 +19,5 @@ export enum LetterTemplate {
DashboardLockedPaymentFailure = 'dashboard-locked-payment-failure',
OrganisationInvitation = 'organisation-invitation',
SocialIdentityLinked = 'social-identity-linked',
+ NoEventsAfterSignup = 'no-events-after-signup',
}
diff --git a/backend/apps/cloud/src/mailer/mailer.service.ts b/backend/apps/cloud/src/mailer/mailer.service.ts
index 25d130e39..5220d5649 100644
--- a/backend/apps/cloud/src/mailer/mailer.service.ts
+++ b/backend/apps/cloud/src/mailer/mailer.service.ts
@@ -114,6 +114,11 @@ const metaInfoJson = {
en: () => 'A social account has been linked to your Swetrix account',
},
},
+ [LetterTemplate.NoEventsAfterSignup]: {
+ subject: {
+ en: () => 'Need help setting up Swetrix?',
+ },
+ },
}
interface Params {
diff --git a/backend/apps/cloud/src/task-manager/task-manager.service.ts b/backend/apps/cloud/src/task-manager/task-manager.service.ts
index 724132e02..70da03f98 100644
--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts
+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts
@@ -104,6 +104,7 @@ const checkQueryCondition = (
const CHUNK_SIZE = 5000
const REPORTS_USERS_CONCURRENCY = 3
const REPORTS_PROJECTS_CONCURRENCY = 5
+const NO_EVENTS_REMINDER_DELAY_DAYS = 2
const mapLimit = async <T, R>(
items: T[],
@@ -501,6 +502,51 @@ export class TaskManagerService {
return `${this.configService.get('CLIENT_URL')}/reports-unsubscribe/${token}`
}
+ async getUserEventsCountSinceSignup(userId: string): Promise<number> {
+ const pids = await this.projectService.getProjectIdsByAdminId(userId)
+
+ if (_isEmpty(pids)) {
+ return 0
+ }
+
+ let totalEvents = 0
+
+ for (let i = 0; i < pids.length; i += CHUNK_SIZE) {
+ const pidChunk = pids.slice(i, i + CHUNK_SIZE)
+ const query = `
+ SELECT sum(cnt) AS totalEvents
+ FROM (
+ SELECT count() AS cnt
+ FROM analytics
+ WHERE pid IN ({pids:Array(FixedString(12))})
+ UNION ALL
+ SELECT count() AS cnt
+ FROM customEV
+ WHERE pid IN ({pids:Array(FixedString(12))})
+ UNION ALL
+ SELECT count() AS cnt
+ FROM captcha
+ WHERE pid IN ({pids:Array(FixedString(12))})
+ UNION ALL
+ SELECT count() AS cnt
+ FROM errors
+ WHERE pid IN ({pids:Array(FixedString(12))})
+ )
+ `
+
+ const { data } = await clickhouse
+ .query({
+ query,
+ query_params: { pids: pidChunk },
+ })
+ .then((resultSet) => resultSet.json<{ totalEvents: any }>())
+
+ totalEvents += Number(data[0]?.totalEvents) || 0
+ }
+
+ return totalEvents
+ }
+
async handleUserReports(
reportFrequency:
| ReportFrequency.WEEKLY
@@ -1058,6 +1104,65 @@ export class TaskManagerService {
})
}
+ @Cron(CronExpression.EVERY_DAY_AT_10AM)
+ async remindUsersWithoutEventsAfterSignup() {
+ const weekAgo = dayjs.utc().subtract(1, 'week').toDate()
+ const twoDaysAgo = dayjs
+ .utc()
+ .subtract(NO_EVENTS_REMINDER_DELAY_DAYS, 'days')
+ .toDate()
+ const users = await this.userService.find({
+ where: {
+ isActive: true,
+ // we don't want to send the reminder for people who for example used it long time ago, then removed their projects and now are kinda counted as "new users"
+ created: Between(weekAgo, twoDaysAgo),
+ noEventsReminderSentOn: IsNull(),
+ },
+ select: ['id', 'email'],
+ })
+
+ if (_isEmpty(users)) {
+ return
+ }
+
+ const dashboardUrl = `${this.configService.get('CLIENT_URL')}/dashboard`
+ const setupGuideUrl = 'https://docs.swetrix.com/install-script'
+ const sentOn = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
+
+ await mapLimit(users, REPORTS_USERS_CONCURRENCY, async (user) => {
+ try {
+ const hasProjects =
+ (await this.projectService.countByAdminId(user.id)) > 0
+
+ if (!hasProjects) {
+ return
+ }
+
+ const totalEvents = await this.getUserEventsCountSinceSignup(user.id)
+
+ if (totalEvents > 0) {
+ return
+ }
+
+ await this.mailerService.sendEmail(
+ user.email,
+ LetterTemplate.NoEventsAfterSignup,
+ {
+ dashboardUrl,
+ setupGuideUrl,
+ },
+ )
+ await this.userService.update(user.id, {
+ noEventsReminderSentOn: sentOn,
+ })
+ } catch (reason) {
+ this.logger.error(
+ `[CRON WORKER](remindUsersWithoutEventsAfterSignup) Failed to process user ${user.id}: ${reason}`,
+ )
+ }
+ })
+ }
+
@Cron(CronExpression.EVERY_2_HOURS)
async deleteOldShareInvitations() {
const minDate = dayjs.utc().subtract(PROJECT_INVITE_EXPIRE, 'h').toDate()
diff --git a/backend/apps/cloud/src/user/entities/user.entity.ts b/backend/apps/cloud/src/user/entities/user.entity.ts
index 48c6d3410..cff1b2550 100644
--- a/backend/apps/cloud/src/user/entities/user.entity.ts
+++ b/backend/apps/cloud/src/user/entities/user.entity.ts
@@ -269,6 +269,10 @@ export class User {
@Column({ type: 'timestamp', nullable: true })
evWarningSentOn: Date
+ // the date when the "no events after signup" reminder email was sent
+ @Column({ type: 'timestamp', nullable: true })
+ noEventsReminderSentOn: Date
+
@Column('varchar', { length: 15, nullable: true })
subID: string
diff --git a/backend/migrations/mysql/2026_02_14_no_events_reminder.sql b/backend/migrations/mysql/2026_02_14_no_events_reminder.sql
new file mode 100644
index 000000000..4853b2bca
--- /dev/null
+++ b/backend/migrations/mysql/2026_02_14_no_events_reminder.sql
@@ -0,0 +1 @@
+ALTER TABLE `user` ADD COLUMN `noEventsReminderSentOn` datetime DEFAULT NULL;