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!

Separate email about trial expiration for people who cancelled early

Blue Mouseac1c910cd7d7
diff --git a/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html b/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html
new file mode 100644
index 000000000..e1bbd8ae1
--- /dev/null
+++ b/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html
@@ -0,0 +1,16 @@
+Hey there,<br /><br />
+
+Just a heads up - your Swetrix trial ends in about 48 hours, and since you've
+cancelled, your subscription won't activate automatically.<br /><br />
+
+Once the trial ends, your dashboard will be locked and you'll lose access to
+your analytics data. Your projects and data won't be deleted, but you won't be
+able to view them until you subscribe to a plan.<br /><br />
+
+If you've changed your mind, you can
+<a href="{{url}}" target="_blank">subscribe from your billing page</a> before
+the trial ends to keep everything running.<br /><br />
+
+Got questions? Just reply to this email β€” we're happy to help.<br /><br />
+
+Andrii Romasiun Founder, Swetrix
diff --git a/backend/apps/cloud/src/mailer/letter.ts b/backend/apps/cloud/src/mailer/letter.ts
index b8a1cb801..374bb474a 100644
--- a/backend/apps/cloud/src/mailer/letter.ts
+++ b/backend/apps/cloud/src/mailer/letter.ts
@@ -12,6 +12,7 @@ export enum LetterTemplate {
TwoFAOff = '2fa-turned-off',
TrialExpired = 'trial-expired',
TrialEndsTomorrow = 'trial-ends-tomorrow',
+ TrialEndingCancelled = 'trial-ending-cancelled',
ProjectSubscriberInvitation = 'project-subscriber-invitation',
ProjectTransfer = 'project-transfer',
UsageOverLimit = 'usage-over-limit',
diff --git a/backend/apps/cloud/src/mailer/mailer.service.ts b/backend/apps/cloud/src/mailer/mailer.service.ts
index 398f810e1..f05d6f9b1 100644
--- a/backend/apps/cloud/src/mailer/mailer.service.ts
+++ b/backend/apps/cloud/src/mailer/mailer.service.ts
@@ -81,6 +81,11 @@ const metaInfoJson = {
en: () => 'Your Swetrix trial ends in 48 hours',
},
},
+ [LetterTemplate.TrialEndingCancelled]: {
+ subject: {
+ en: () => 'Your Swetrix trial ends in 48 hours β€” action needed',
+ },
+ },
[LetterTemplate.ProjectSubscriberInvitation]: {
subject: {
en: () => 'You have been invited to join the project',
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 91a6b18d2..e221ca556 100644
--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts
+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts
@@ -1371,22 +1371,23 @@ export class TaskManagerService {
),
trialReminderSent: false,
},
- select: ['id', 'email'],
+ select: ['id', 'email', 'cancellationEffectiveDate'],
})
const promises = _map(users, async (user) => {
- const { id, email } = user
+ const { id, email, cancellationEffectiveDate } = user
await this.userService.update(id, {
trialReminderSent: true,
})
- await this.mailerService.sendEmail(
- email,
- LetterTemplate.TrialEndsTomorrow,
- {
- url: 'https://swetrix.com/user-settings?tab=billing',
- },
- )
+
+ const template = cancellationEffectiveDate
+ ? LetterTemplate.TrialEndingCancelled
+ : LetterTemplate.TrialEndsTomorrow
+
+ await this.mailerService.sendEmail(email, template, {
+ url: 'https://swetrix.com/user-settings?tab=billing',
+ })
})
await Promise.allSettled(promises).catch((reason) => {
diff --git a/backend/apps/cloud/src/webhook/webhook.controller.ts b/backend/apps/cloud/src/webhook/webhook.controller.ts
index aec883260..27928352d 100644
--- a/backend/apps/cloud/src/webhook/webhook.controller.ts
+++ b/backend/apps/cloud/src/webhook/webhook.controller.ts
@@ -211,16 +211,20 @@ export class WebhookController {
cancellationEffectiveDate,
})
- const { email } =
- (await this.userService.findOne({
- where: { subID },
- })) || {}
+ const user = await this.userService.findOne({
+ where: { subID },
+ })
- if (email) {
- await this.mailerService.sendEmail(
- email,
- LetterTemplate.SubscriptionCancelled,
- )
+ if (user?.email) {
+ const isTrialing =
+ user.trialEndDate && new Date(user.trialEndDate) > new Date()
+
+ if (!isTrialing) {
+ await this.mailerService.sendEmail(
+ user.email,
+ LetterTemplate.SubscriptionCancelled,
+ )
+ }
}
break