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!

added support for quarterly reports

Blue Mouse6009edf38e38
diff --git a/src/common/templates/en/project-report.html b/src/common/templates/en/project-report.html
index e7db06960..4a653ba22 100644
--- a/src/common/templates/en/project-report.html
+++ b/src/common/templates/en/project-report.html
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Swetrix {{#ifEquals type "w"}}Weekly{{/ifEquals}}{{#ifEquals type "M"}}Monthly{{/ifEquals}} Project Report</title>
+ <title>Swetrix {{#ifEquals type "w"}}Weekly{{/ifEquals}}{{#ifEquals type "M"}}Monthly{{/ifEquals}}{{#ifEquals type "Q"}}Quarterly{{/ifEquals}} Project Report</title>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700" rel="stylesheet" />
</head>
<body style="margin: 0; padding: 0; background-color: #f0f4f7;">
@@ -42,7 +42,7 @@
align="center"
style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 44px; color: #1a1a1a;"
>
- {{#ifEquals type "w"}}Weekly{{/ifEquals}}{{#ifEquals type "M"}}Monthly{{/ifEquals}} Report
+ Your {{#ifEquals type "w"}}Weekly{{/ifEquals}}{{#ifEquals type "M"}}Monthly{{/ifEquals}}{{#ifEquals type "Q"}}Quarterly{{/ifEquals}} Report
</span>
</font>
<div style="height: 10px; line-height: 10px; font-size: 9px;">&nbsp;</div>
diff --git a/src/task-manager/task-manager.service.ts b/src/task-manager/task-manager.service.ts
index 9ccf43a6c..91aba2104 100644
--- a/src/task-manager/task-manager.service.ts
+++ b/src/task-manager/task-manager.service.ts
@@ -311,7 +311,39 @@ export class TaskManagerService {
@Cron(CronExpression.EVERY_QUARTER)
async handleQuarterlyReports(): Promise<void> {
- // TODO: Implement
+ const subscribers = await this.projectService.getSubscribersForReports(
+ ReportFrequency.QUARTERLY,
+ )
+ const now = dayjs.utc().format('DD.MM.YYYY')
+ const quarterAgo = dayjs.utc().subtract(3, 'M').format('DD.MM.YYYY')
+ const date = `${quarterAgo} - ${now}`
+ const tip = getRandomTip()
+
+ for (const subscriber of subscribers) {
+ const projects = await this.projectService.getSubscriberProjects(
+ subscriber.id,
+ )
+
+ const ids = projects.map(project => project.id)
+ const data = await this.analyticsService.getSummary(ids, 'M')
+
+ const result = {
+ type: 'Q', // quarter
+ date,
+ projects: _map(ids, (pid, index) => ({
+ data: data[pid],
+ name: projects[index].name,
+ })),
+ tip,
+ }
+
+ await this.mailerService.sendEmail(
+ subscriber.email,
+ LetterTemplate.ProjectReport,
+ result,
+ 'broadcast',
+ )
+ }
}
// ON THE FIRST DAY OF EVERY MONTH AT 3 AM