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!

PR review fixes

Blue Mouse0c4027cbd61d
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 44ac6e1a5..c1a1d79ed 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -548,6 +548,7 @@ export class AnalyticsService {
safeTimezone: string,
diff?: number,
checkTimebucket = true,
+ now?: dayjs.Dayjs,
): IGetGroupFromTo {
let groupFrom: dayjs.Dayjs
let groupTo: dayjs.Dayjs
@@ -555,9 +556,13 @@ export class AnalyticsService {
let groupToUTC: string
const formatFrom = 'YYYY-MM-DD HH:mm:ss'
const formatTo = 'YYYY-MM-DD HH:mm:ss'
- const djsNow = _includes(GMT_0_TIMEZONES, safeTimezone)
- ? dayjs.utc()
- : dayjs().tz(safeTimezone)
+ const djsNow = now
+ ? _includes(GMT_0_TIMEZONES, safeTimezone)
+ ? dayjs.utc(now.toDate())
+ : dayjs(now.toDate()).tz(safeTimezone)
+ : _includes(GMT_0_TIMEZONES, safeTimezone)
+ ? dayjs.utc()
+ : dayjs().tz(safeTimezone)
if (!_isEmpty(from) && !_isEmpty(to)) {
if (!isValidDate(from)) {
@@ -1639,6 +1644,7 @@ export class AnalyticsService {
timezone?: string,
filters?: string,
includeChart?: boolean,
+ now?: dayjs.Dayjs,
): Promise<IOverall> {
const safeTimezone = this.getSafeTimezone(timezone)
@@ -1658,6 +1664,7 @@ export class AnalyticsService {
safeTimezone,
undefined,
false,
+ now,
)
const result = {}
diff --git a/backend/apps/cloud/src/common/templates/en/project-report.html b/backend/apps/cloud/src/common/templates/en/project-report.html
index 60f618cd4..45203d5bb 100644
--- a/backend/apps/cloud/src/common/templates/en/project-report.html
+++ b/backend/apps/cloud/src/common/templates/en/project-report.html
@@ -126,7 +126,7 @@
font-size: 14px;
font-weight: 500;
margin-left: 6px;
- {{#greater data.percChangeUsers 0}}color: #059669;{{else}}color: #DC2626;{{/greater}}
+ {{#greater data.percChangeUsers 0}}color: #059669;{{else}}{{#less data.percChangeUsers 0}}color: #DC2626;{{else}}color: #64748b;{{/less}}{{/greater}}
">{{#greater data.percChangeUsers 0}}+{{/greater}}{{data.percChangeUsers}}%</span>
</td>
</tr>
@@ -158,7 +158,7 @@
font-size: 14px;
font-weight: 500;
margin-left: 6px;
- {{#greater data.percChangeUnique 0}}color: #059669;{{else}}color: #DC2626;{{/greater}}
+ {{#greater data.percChangeUnique 0}}color: #059669;{{else}}{{#less data.percChangeUnique 0}}color: #DC2626;{{else}}color: #64748b;{{/less}}{{/greater}}
">{{#greater data.percChangeUnique 0}}+{{/greater}}{{data.percChangeUnique}}%</span>
</td>
</tr>
@@ -190,7 +190,7 @@
font-size: 14px;
font-weight: 500;
margin-left: 6px;
- {{#greater data.percChangePageviews 0}}color: #059669;{{else}}color: #DC2626;{{/greater}}
+ {{#greater data.percChangePageviews 0}}color: #059669;{{else}}{{#less data.percChangePageviews 0}}color: #DC2626;{{else}}color: #64748b;{{/less}}{{/greater}}
">{{#greater data.percChangePageviews 0}}+{{/greater}}{{data.percChangePageviews}}%</span>
</td>
</tr>
diff --git a/backend/apps/cloud/src/common/utils.ts b/backend/apps/cloud/src/common/utils.ts
index d431c99a0..34cade399 100644
--- a/backend/apps/cloud/src/common/utils.ts
+++ b/backend/apps/cloud/src/common/utils.ts
@@ -328,7 +328,7 @@ export const sumArrays = (source: number[], target: number[]) => {
* @returns Formatted duration string
*/
export const formatDuration = (seconds: number | null | undefined): string => {
- if (!seconds || seconds <= 0) return '0s'
+ if (seconds == null || !Number.isFinite(seconds) || seconds <= 0) return '0s'
const roundedSeconds = Math.round(seconds)
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 236c27c87..4de096ffe 100644
--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts
+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts
@@ -29,6 +29,7 @@ import { ActionTokenType } from '../action-tokens/action-token.entity'
import { LetterTemplate } from '../mailer/letter'
import { AnalyticsService } from '../analytics/analytics.service'
import { SaltService } from '../analytics/salt.service'
+import { TimeBucketType } from '../analytics/dto/getData.dto'
import { PayoutsService } from '../payouts/payouts.service'
import { GoalService } from '../goal/goal.service'
import { Goal, GoalType, GoalMatchType } from '../goal/entity/goal.entity'
@@ -306,24 +307,31 @@ export class TaskManagerService {
goal: Goal,
_table: 'analytics' | 'customEV',
): { condition: string; params: Record<string, string> } {
+ const goalValue = (goal.value ?? '').toString()
+
+ // If goal value is blank, never match anything (avoid LIKE '%%')
+ if (goalValue.trim() === '') {
+ return { condition: '1=0', params: {} }
+ }
+
const params: Record<string, string> = {}
if (goal.type === GoalType.CUSTOM_EVENT) {
if (goal.matchType === GoalMatchType.EXACT) {
- params.goalValue = goal.value || ''
+ params.goalValue = goalValue
return { condition: `ev = {goalValue:String}`, params }
} else {
- params.goalValue = `%${goal.value || ''}%`
+ params.goalValue = `%${goalValue}%`
return { condition: `ev LIKE {goalValue:String}`, params }
}
}
// Pageview goal
if (goal.matchType === GoalMatchType.EXACT) {
- params.goalValue = goal.value || ''
+ params.goalValue = goalValue
return { condition: `pg = {goalValue:String}`, params }
} else {
- params.goalValue = `%${goal.value || ''}%`
+ params.goalValue = `%${goalValue}%`
return { condition: `pg LIKE {goalValue:String}`, params }
}
}
@@ -429,9 +437,18 @@ export class TaskManagerService {
const date = `${timeAgoFormatted} - ${nowFormatted}`
const tip = getRandomTip()
- // Date range for additional queries
- const groupFrom = timeAgo.format('YYYY-MM-DD 00:00:00')
- const groupTo = now.format('YYYY-MM-DD 23:59:59')
+ // Date range for additional queries (must match summary period + cron execution timestamp)
+ const safeTimezone = this.analyticsService.getSafeTimezone(undefined)
+ const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(
+ '',
+ '',
+ TimeBucketType.DAY,
+ params.analyticsParam,
+ safeTimezone,
+ undefined,
+ false,
+ now,
+ )
const promises = _map(users, async user => {
const { id, email, projects } = user
@@ -444,6 +461,12 @@ export class TaskManagerService {
ids,
undefined,
params.analyticsParam,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ now,
),
)
@@ -551,9 +574,18 @@ export class TaskManagerService {
const date = `${timeAgoFormatted} - ${nowFormatted}`
const tip = getRandomTip()
- // Date range for additional queries
- const groupFrom = timeAgo.format('YYYY-MM-DD 00:00:00')
- const groupTo = now.format('YYYY-MM-DD 23:59:59')
+ // Date range for additional queries (must match summary period + cron execution timestamp)
+ const safeTimezone = this.analyticsService.getSafeTimezone(undefined)
+ const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(
+ '',
+ '',
+ TimeBucketType.DAY,
+ params.analyticsParam,
+ safeTimezone,
+ undefined,
+ false,
+ now,
+ )
const promises = _map(subscribers, async subscriber => {
const { id, email } = subscriber
@@ -567,6 +599,12 @@ export class TaskManagerService {
ids,
undefined,
params.analyticsParam,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ now,
),
)